# How can I keep everything within a variable/macro on the same line?

I know there are various techniques to keep things on the same line. I have a two-word variable input. For example, Settings App.

Let's say there are a group of apps, and I would like them always formatted the same.

I could go about this different ways. The straightforward solution is to write each one manually:

\textit{Settings~App}


This is not really a good solution, because I cannot differentiate between other \textit{} text and \textit{} app text.

So, I put it into a variable/macro.

\newcommand\app[1]{\textit{#1}}
\app{Settings App}


or LaTeX3 syntax

\usepackage{xparse}
\NewDocumentCommand{\app}{m}{\textit{#1}}
\app{Settings App}


The problem is, other people who might be writing text will forget the tilde. The consequence is not ensuring an unlinebreakable space and not being able to easily search for occurrences of an app name.

So, my question is whether there is something I can add into my macro definition above that will ensure a non-linebreakable space without the explicit tilde?

• How about an \mbox{...}? – sodd Apr 19 '16 at 5:04
• @hooy Is \mbox{} not linebreakable? That would be easy. – Jonathan Komar Apr 19 '16 at 5:04
• It is not linebreakable, no. – sodd Apr 19 '16 at 5:06
• @hooy Please provide an answer and let's get this thing wrapped up then :) – Jonathan Komar Apr 19 '16 at 5:08

You can use one of the horizontal boxes, for example \mbox, as that will not allow linebreaks. For more examples of horizontal boxes, see @egreg's answer here. Although \mbox prevents linebreaks, it will have the side effect of not stretching or shrinking with the rest of the text, see @egreg's answer here for a solution to such a problem.

So a "quick, easy fix" would be as follows:

\newcommand\app[1]{\mbox{\textit{#1}}}
\app{Settings App}


or

\usepackage{xparse}
\NewDocumentCommand{\app}{m}{\mbox{\textit{#1}}}
\app{Settings App}