# Auto spacing in math mode

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 asverylongword 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? • 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 '15 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 '15 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 '15 at 14:41 • Simply put, that text isn't being hyphenated because you don't hyphenate multiplied variables. – Sean Allred Mar 31 '15 at 21:32 ## 1 Answer 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. \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. \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}  • 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 '15 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? – David Carlisle Mar 31 '15 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 '15 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 '15 at 20:18
• As mentioned before, it is highly preferable to have it within a single line. – Saulius S Mar 31 '15 at 20:45