Troubleshooting Latex: Can't Generate Multiple Lines in a Single [tex] Block?

  • LaTeX
  • Thread starter Redbelly98
  • Start date
  • Tags
    Latex Line
In summary: This one gives the expected results:In summary, the double-backslash "problem" is that the forum software places us in a \LaTeX environment... and these \[ \] break us out of it somehow.
  • #1
Redbelly98
Staff Emeritus
Science Advisor
Homework Helper
Insights Author
12,175
182
I can't seem to generate multiple lines within a single [ tex ][ /tex ] block. It's supposed to happen if I type \\ but it just never works for me.

Example:

[tex]
f_1(x) = x \\
f_2(x) = 1-x^2
[/tex]

The "f2(x)" is supposed to start on a new line.

What am I doing wrong?
 
Last edited:
Physics news on Phys.org
  • #2
Redbelly98 said:
I can't seem to generate multiple lines within a single [ tex ][ /tex ] block. It's supposed to happen if I type \\ but it just never works for me.

Example:

[tex]
f_1(x) = x \\
f_2(x) = 1-x^2
[/tex]

The "f2(x)" is supposed to start on a new line.

What am I doing wrong?

Unfortunately I'm not going to be of any help to you. I've also tried this numerous times, but to the same effect.
 
  • #3
I don't think that the \\ has ever worked on the forums, it must be some kind of bug in the software. However, one can start new lines using the flalign environment.

[tex]
\begin{flalign*}
f_1\left(x\right) & = & & x\\
f_2\left(x\right) & = & & 1-x^2\\
f_3\left(x\right) & = & & \frac{f_1}{f_2} \\
& = & & \frac{x}{1-x^2}
\end{flalign*}
[/tex]

And the code:
Code:
\begin{flalign*}
f_1\left(x\right) & = & & x\\
f_2\left(x\right) & = & & 1-x^2\\
f_3\left(x\right) & = & & \frac{f_1}{f_2} \\
& = & & \frac{x}{1-x^2}
\end{flalign*}

The * is used to suppress line enumeration. The alignment of each element is fixed to alternate between left and right as shown below

Code:
\begin{flalign*}
right & left & right & ... \\
right & left & right & ... \\
right & left & right & ... \\
\end{flalign*}

But you can add additional & separators to obtain the desired layout, as I have done above:

Code:
\begin{flalign*}
right & left &  & left \\
right & left &  & left \\
right & left &  & left \\
\end{flalign*}

I agree that this method is far more verbose than simply using \\ is mathmode, but it is the only work-a-round that i know of for PF. Note that the eqnarray environment does not display correctly either at PF.
 
  • #4
Thanks Hoot. So the &'s help line up the equal signs. And if I just wanted to left-justify each line, each line would start with a &.

Code:
      \begin{flalign*}
      & f_1(x) = x \\ 
      & f_2(x) = 1-x^2
      \end{flalign*}

I also found this previous discussion in a locked thread:
https://www.physicsforums.com/showthread.php?t=8997&highlight=latex+line&page=19

However, in chroot's examples the code uses TWO begin and TWO end statements, eg.
\begin{equation*}
\begin{split}

So the single begin statement
\begin{flalign*}
is an improvement over that.

Thanks again!

RB
 
  • #5
Hootenanny said:
II don't think that the \\ has ever worked on the forums
I've never known it to work in LaTeX either. (Remember that [ itex ] ... [/itex] is analogous to $ ... $, and [ tex ] ... [/tex] is analogous to \[ ... \])
 
  • #6
Hurkyl said:
I've never known it to work in LaTeX either. (Remember that [ itex ] ... [/itex] is analogous to $ ... $, and [ tex ] ... [/tex] is analogous to \[ ... \])
Hmm, you're quite right: \\ only works in array enviroments in LaTeX :redface:
 
  • #7
[tex]
\]
This is the first line.\\
This is the second line.\\
This is the third line.
\[
E=mc^2
\]
This is another line.
\[
[/tex]

Click on the rendered image to see what I did.
Maybe some [tex]\LaTeX[/tex] expert can explain what is going on.
I suspect that the forum software already places us in a [tex]\LaTeX[/tex] environment... and these \[ \] break us out of it somehow.
 
Last edited:
  • #8
robphy said:
I suspect that the forum software already places us in a [tex]\LaTeX[/tex] environment... and these \[ \] break us out of it somehow.

Sounds precisely right to me: the [tex] tag acts like \[ and by typing \], you close the latex environment.
 
  • #9
Now that we are using MathJax, I am revisiting how to generate multiple lines within a single LaTeX code block.

EDIT: Nevermind, I found out how to do this: https://www.physicsforums.com/showthread.php?p=261329

Also, scroll down post #1 here for multi-line examples: https://www.physicsforums.com/showthread.php?t=8997

Please disregard the following...


I just now noticed a problem with these old posts (for example Post #'s 1 and 3 above). Right now I see the LaTeX code, without the [_tex_] tags, enclosed in a box and left-right centered in the page. I have FireFox 4 and Windows 7.

Apparently MathJax doesn't like the double-backslash newline indicator, and that is preventing the code from being processed properly.

Testing:

Using same code from Post #1 again:
[tex]
f_1(x) = x \\
f_2(x) = 1-x^2
[/tex]

Same code, with double-backslash removed:
[tex]
f_1(x) = x
f_2(x) = 1-x^2
[/tex]

So the question is, is it possible anymore to generate a new line within the same [_tex_] code block? Hootenanny's trick in Post #3 used to work -- not that I am advocating going back to the old LaTeX system.
 
Last edited:
  • #10
Here:
[tex]
\begin{align}
a & b \\
c & d
\end{align}
[/tex]

This one gives weird results:
[tex]
\begin{multline}
a b \\
c d
\end{multline}
[/tex]
 

What is the purpose of using [tex] blocks in Latex?

The [tex] block in Latex is used to display mathematical equations and expressions in a document. It allows for precise formatting and editing of mathematical content.

Why am I unable to generate multiple lines in a single [tex] block?

This is most likely due to a syntax error or missing command in your code. Make sure that each line of the equation is separated by a double backslash (\\) and that all commands are properly closed with a curly brace (}).

How can I troubleshoot and fix this issue?

One way to troubleshoot this issue is by checking the syntax of your code and making sure all necessary commands are included. You can also try compiling your code in a Latex editor or online compiler to see if it produces any error messages or warnings.

Are there any common mistakes that can lead to this problem?

Yes, some common mistakes include forgetting to close commands with curly braces, using incorrect syntax for line breaks or special characters, and not including the necessary packages for mathematical expressions in your document.

Is there a way to display multiple lines without using a [tex] block?

Yes, you can use the align environment to display multiple lines of equations without using a [tex] block. This environment requires the amsmath package and allows for easy formatting and alignment of equations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
731
  • Special and General Relativity
Replies
10
Views
549
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
222
Replies
15
Views
4K
  • Introductory Physics Homework Help
Replies
10
Views
486
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
5K
Back
Top