# Which one is preferred to write x-axis as a single unit that cannot be hyphenated?

Which one is preferred to write x-axis as a single unit that cannot be hyphenated by LaTeX?

\documentclass[preview,varwidth]{standalone}
\usepackage{amsmath}
\begin{document}
\preview
Along the $x\text{-axis}$,
\endpreview

\preview
Along the \mbox{$x$-axis},
\endpreview
\end{document}


As a completeness, I don't think

Along the $x$-axis,


is recommended because hyphenation may sometimes occur.

-

As far as I know, the options are equivalent output-wise, so the question is about a semantic choice.

In my opinion then, the answer is the same as for all compound words containing math elements : they are words you use in an english sentence, not in a math formula. So the latter option would make more sense.

And since I'm lazy, I wouldn't bother writing \mbox{...} all the time, I would just add it in the final version of the document where needed.

-

Let me note that there is not any typographical rule that states that the below method is any way correct. It can merely be used if one wishes to control the dash's placement.

One way to do this is to add a command which adds a non-hyphenated dash.

This can be done with \nobreakdash. However, this will not allow any hyphenation until the next word (i.e. no hyphenation in the axis word). Thus one should add a space which breaks the words

A solution would be

% Requires amsmath package
\def\dirdash{\nobreakdash-\hspace{0pt}}


This will show this:

\documentclass{article}
\usepackage{geometry,amsmath}
\geometry{paperheight=5cm,paperwidth=6cm,textheight=3cm,textwidth=4cm}
\def\dirdash#1{\nobreakdash#1\hspace{0pt}}
\begin{document}
Hello, this is the a $x$-axis

Hello, this is the a $x$\dirdash-axis

Hello, this is the a $x$-longword

Hello, this is the a $x$\dirdash-longword
\end{document}


And yield the following output

-
Preventing hyphenation in compound words is the default behavior, even without \nobreakdash. See for example this question : stackoverflow.com/questions/2193307/… . You may want to bypass this from time to time, but I would disadvise making it a global setting. –  T. Verron Feb 14 '13 at 10:02
Exactly what do you mean? Maybe, I have misinterpreted the request. I would not use this \dirdash on every dash. It seemed that it was only requested at the mathematical descriptors $x$-<something>? –  zeroth Feb 14 '13 at 10:07
Even in mathematical descriptors. I'm no typographist, so I follow blindly the typographical rules, as much as possible. If latex does not want to add an hyphen in the middle of "axis", I don't think it's a good idea to bypass this "safety measure" every time one uses the expression "$x$-axis". Instead, I'd suggest to add \- at the wanted hyphenation point in $x$-<somethinglong>, only when needed. –  T. Verron Feb 14 '13 at 10:20
Why "of course"? Try it in a real document, having two hyphens (one dash and one end-of-line hyphen) in the same word definitely looks weird to me. See for example : i.imgur.com/dY5bGxJ.png . Once again, from time to time, it's still a better choice than an overfull hbox. But for the default setting, I still prefer to let latex try to play with its glues and stretchable spaces as hard as it can, before it tells me I have to force the hyphenation. –  T. Verron Feb 14 '13 at 10:33
Yes, great, example. I think we agree, that generally any hyphenation should not be controlled. I simply added a way to control it (in the way that @GarbageCollector seemed to request). –  zeroth Feb 14 '13 at 10:37