0

I have a long line of math expression, which is as follows:

$verylongword verylongword verylongword verylongword verylongword verylongword verylongword verylongword verylongword verylongword verylongword verylongword$

The problem is that the expressions denoted "verylongword" cannot be hyphenated to "very-long-word".

This results that in math mode the i can split text putting additional $ and \ (new lines). This means that some of the line ends are left as empty spaces, and text is not aligned properly, i.e. spacing between math is fixed and text is seen as $verylongword verylongword verylongword $(10 empty spaces).

Is there a way how to align such line in a nice automatic way, so as words within math expression would be automatically aligned adding extra spaces between math text?

4
  • 2
    Welcome to TeX.SX! Normally one does not have long words in math mode (except maybe in a \text macro), so can you be a bit more precise about what you are doing and want to achieve?
    – moewe
    Mar 31, 2015 at 14:33
  • I would say that normally mathematicians don't have long words in math mode. For us normal mortals belonging to fields that doesn't know better we often find ourselves needing long words in math mode...
    – jonalv
    Mar 31, 2015 at 14:37
  • ...however, those mathematicians have a point, after all mathematics is their expertise. So having long words in math mode means special solutions for each special case in my humble experience. Hence, be as specific as possible in explaining what you want to do.
    – jonalv
    Mar 31, 2015 at 14:41
  • Simply put, that text isn't being hyphenated because you don't hyphenate multiplied variables. Mar 31, 2015 at 21:32

1 Answer 1

3

The default in inline math mode is to stretch white space and justify lines to the specified width, if that is not happening in your real example you will need to show your real example.

enter image description here

\documentclass{article}

\begin{document}

$\mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}$

\end{document}

Note I used \mathit here as you should never set multi-letter words in the default math italic font.

Depending on the text you may want to let white space stretch more than usual, eg \sloppy on the example in comments.

enter image description here

\documentclass{article}
 \begin{document}

\noindent X\dotfill X

{\sloppy
  $\mathit{verylongword}+ \mathit{verylongword12}+
  \mathit{verylongword12}+ \mathit{verylongword12}+
  \mathit{verylongword12}+ \mathit{verylongword12}+
  \mathit{verylongword12}+ \mathit{verylongword}+
  \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+
  \mathit{verylongword}$

}



\bigskip

{\raggedright
   $\mathit{Accuracy(ID=1)=0.75}$,
   $\mathit{Accuracy(ID=2)=0.74}$,
   $\mathit{Accuracy(ID=3)=0.72}$

}

\bigskip

{
   $\mathit{Accuracy(ID=1)=0.75}$,\hfill
   $\mathit{Accuracy(ID=2)=0.74}$,\hfill
   $\mathit{Accuracy(ID=3)=0.72}$

}
\end{document}
6
  • Hi, this is my case, but the problem is that page width ends in the middle of "verylongword" and tex does not put in on new line by default. For this i add \\ and this makes unused spaces in the end of the line as spacing between previous words does not work. @jonalv - math part is function names and results that should be kept on the same line.
    – Saulius S
    Mar 31, 2015 at 15:08
  • @SauliusS the point of posting example code in the question is to demonstrate the problem you are having Posting error free code which is unrelated to your problem is just a waste of time. You need to fix your question so that your example is a complete document (as here) and shows a bad line break. There are 10000s of reasons why in some cases TeX needs help to break difficult material that can not be hyphenated (which is always the case in math) why make us guess? Mar 31, 2015 at 15:48
  • \documentclass{article} \begin{document} $\mathit{verylongword}+ \mathit{verylongword12}+ \mathit{verylongword12}+ \mathit{verylongword12}+ \mathit{verylongword12}+ \mathit{verylongword12}+ \mathit{verylongword12}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}+ \mathit{verylongword}$ \end{document} this is an example, where the second line is not aligned. Is there a way how to make it with automatic equal spacing? sorry for bad formatting
    – Saulius S
    Mar 31, 2015 at 18:58
  • unluckily for some parts it still not work even with sloppy {\sloppy $\mathit{Accuracy(ID=1)=0.75}, \mathit{Accuracy(ID=2)=0.74}, \mathit{Accuracy(ID=3)=0.72}$} - in such case last 0.72 (4 elements are not within the page text width.
    – Saulius S
    Mar 31, 2015 at 20:18
  • As mentioned before, it is highly preferable to have it within a single line.
    – Saulius S
    Mar 31, 2015 at 20:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .