How to Write a Function in LaTeX (Not PF Version)?

  • LaTeX
  • Thread starter quasar987
  • Start date
  • Tags
    Latex
In summary: You can specify the alignment for each column by using &.In summary, the conversation discusses how to write a function in LaTeX with proper alignment of the arrows, regardless of the length of the inputs. Various suggestions are given, including using '&' to align all elements, using the \phantom{} macro to extend the arrow, and using the amsmath align environment.
  • #1
quasar987
Science Advisor
Homework Helper
Gold Member
4,807
32
How would I go about to write in latex (not the PF version, the actual thing) a function? By that, I mean when you go

[tex]f:A\rightarrow B[/tex]
[tex]a\mapsto f(a)[/tex]

but how to write the code so that the arrows are all just right in length?

Thx!
 
Physics news on Phys.org
  • #2
What do you meany by "just right in length"?
 
  • #3
I am looking for a command, if it exist, that will make it so a and f(a) will automatically have the right alignment with A and B respectively, and this, independantly of what A,B,a and f(a) are.
 
  • #4
Do you mean aligning the arrows like the equal signs are lined up here:

2vkbvb6.jpg


If so, simply surround whatever you want everything to align to with &'s. So for this, it was putting "&=&" to align all the equal signs.
 
  • #5
No. For instance, if I take A to be very long, the formula will look ugly:

[tex]f:A set that's very long to write outtttt\rightarrow B[/tex]
[tex]a\mapsto f(a)[/tex]

Here, the problem is that f(a) is not aligned with B. I could fix this my making the mapsto arrow longer, but I was hoping for a command like \definefunction{f}{A}{B}{a}{f(a)} that would set everything right automarically.
 
  • #6
Oh, I see what you mean: aligning the arrows would align all. That's clever, thanks :)
 
  • #7
I'm not sure exactly what you are trying to do, but the \phantom{} macro works out what size its argument would be if it was typeset, and then creates an invisible object the same size. Maybe you could use that to extend your arrow using a \phantom copy of the long definition.

EDIT: simultaneous post with your #6 !
 
  • #8
The amsmath align environment should work for that.
 

What is LaTeX and why is it used for writing functions?

LaTeX is a document preparation system that is commonly used for typesetting mathematical and scientific documents. It is popular for writing functions because it has built-in features for displaying equations and symbols with precision and clarity.

How do I define a function in LaTeX?

To define a function in LaTeX, you can use the command \newcommand{\functionname}{expression} where "functionname" is the name of your function and "expression" is the mathematical expression or equation that defines the function. You can then use this command throughout your document to display the function.

Can I use LaTeX to write functions in different programming languages?

Yes, you can use LaTeX to write functions in various programming languages such as Python, Java, and C++. You can use packages like listings or minted to include code snippets and syntax highlighting in your document.

What are some common mistakes to avoid when writing functions in LaTeX?

One common mistake is forgetting to use the appropriate math mode for displaying equations and symbols. Another mistake is not properly defining the arguments and parameters of the function in the command. It is also important to check for any missing or extra curly braces, as they can affect the output of the function.

How can I make my LaTeX functions more visually appealing?

You can use packages like amsmath and amssymb to access a wide range of mathematical symbols and formatting options. You can also use the \displaystyle command to make equations appear in a larger size. Additionally, you can customize the font, color, and layout of your function using the appropriate LaTeX commands.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
380
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
797
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
905
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Back
Top