I'm writing a document where I frequently refer to some experimental cases which are called things like "M-1" and "P-2". It's always a single number, a hyphen, and a single number. In several places, I'm finding these case names broken across two lines with the number and hyphen on the first line and the number on the second line. Is there a way to tell the document never to break these words across two lines aside from using \mbox
or \nobreakdash
at every instance?
My hope would be to define something globally, like the opposite of the \hyphenation
command, specifically for these case names (there's 7 of them). I'd prefer to avoid changing setting which would affect other words in the document, like \exhyphenpenalty=10000
.
If using \mbox
or \nobreakdash
is the best option, what's the difference between the two?
As suggested by Dan and David I tried setting up
\renewcommand{\P}{P\nobreakdash}
(and the same for the other cases, except M, which used \newcommand
) So that I would still have the text P-1 in the text for searching purposes. In the text of the document, it works fine. However, sometimes I name the cases in figure captions, and the document has to include a list of figures. The case name shows up fine in the figure caption, but in the list of figures, I get a missing control sequence error. With a caption of:
\caption[For case P-1.]{For case P-1, more words.}
,
the lof output file reads
\contentsline {figure}{\numberline {4.1}{\ignorespaces For case P\unhbox \voidb@x \toks@ \@emptytoks \def 1{\toks@ {--}\futurelet \@let@token \setbox \z@ \hbox {-\penalty \@M }\unhbox \z@ }\def \setbox \z@ \hbox {-\penalty \@M }\unhbox \z@ {\setbox \z@ \hbox {-\penalty \@M }\unhbox \z@ }\futurelet \@let@token \setbox \z@ \hbox {-\penalty \@M }\unhbox \z@ -1.}}{64}{figure.caption.62}
.
The text of the document says "For case P------1" (the first hyphen is sometimes an different character that's the same length, but gray and slightly lower, and sometimes it's a regular hyphen). This is happening for all of the cases, except the L cases. All of which occur before this error in the list of figures. Although I tried changing one of the references to P-1 that was giving this error to L-1, and the error went away for that caption.
\newcommand\expcase[1]{\mbox{#1}}
...\expcase{M-1}
\newcommand{\M}[1]{\mbox{M-#1}}
and similar for\P
. Used like\M{1}
and\P{2}
. I'm assuming there might be several with the same prefix and just different numbers.