1

Sadly, I am not able to recreate a MWE since I'm working on a fairly complex template. I cannot understand how LaTeX decides to break lines, I googled but I couldn't find a clear cut answer. This is the code I'm working with:

\begin{itemize}
    
% [...]

\item A TOSCA requirement definition within a node type definition was encoded with the term
    \texttt{requirement(}$RName$\texttt{, }$RCap$\texttt{, }$RNType$\texttt{, }$RRel$\texttt{, occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$ is an atom for the name of the 
    requirement, $RCap$ is an atom for the required capability, $RNType$ is an atom for the type of nodes admitted 
    as a target (including subtypes), $RRel$ is an atom representing the relationship underlying the requirement, 
    and $ROccLB$ and $ROccUB$ are respectively lower and upper bound for the number of occurrences of the 
    requirement, $ROccUB$ possibly being the atom \texttt{unbounded};

% [...]

\end{itemize}

The item is typeset like this:

If I add a newline (a literal newline, not a \\, followed by indentation) after the first occurrence of $RRel$ in the code, the line is broken correctly after $ROccLB$, like so:

I get it that LaTeX works in mysterious ways, but I would like to understand this behaviour.


MWE

enter image description here

\documentclass{article}

\addtolength\textwidth{45pt}
\begin{document}

\begin{itemize}
    

\item A TOSCA requirement definition within a node type definition was
  encoded with the term \texttt{requirement(}$RName$\texttt{,
  }$RCap$\texttt{, }$RNType$\texttt{, }$RRel$\texttt{,
    occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
  is an atom for the name of the requirement, $RCap$ is an atom for
  the required capability, $RNType$ is an atom for the type of nodes
  admitted as a target (including subtypes), $RRel$ is an atom
  representing the relationship underlying the requirement, and
  $ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
  number of occurrences of the requirement, $ROccUB$ possibly being
  the atom \texttt{unbounded};


\item A TOSCA requirement definition within a node type definition was
  encoded with the term \texttt{requirement(}$RName$\texttt{,
  }$RCap$\texttt{, }$RNType$\texttt{, }$RRel$ \texttt{,
    occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
  is an atom for the name of the requirement, $RCap$ is an atom for
  the required capability, $RNType$ is an atom for the type of nodes
  admitted as a target (including subtypes), $RRel$ is an atom
  representing the relationship underlying the requirement, and
  $ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
  number of occurrences of the requirement, $ROccUB$ possibly being
  the atom \texttt{unbounded};



\end{itemize}
\end{document}
4
  • 2
    it looks very odd that you use math for this. And why is the comma in typewriter?? Feb 1, 2022 at 12:08
  • in math \texttt is like \mbox and an unbreakable box. I would have used \mathtt and only around each identifier separately not around the ( or , (italic names like RNmae should be in \mathit not the default math font which is designed to make adjacent letters look like a product of 1-letter variables not a word. the newline (a space would be the same) is adding an inter-word space so an allowed line breaking point. Feb 1, 2022 at 12:19
  • 1
    You can always provide a MWE the complexity of the original document is not releavant the only thing that affects the linebreaking here is the font and the text width. I added a document showing the original overfull line and the version with the extra space added where you suggested. Feb 1, 2022 at 12:30
  • Thanks for the MWE, I didn't know what to look for. Feb 1, 2022 at 12:42

3 Answers 3

1

I wouldn't use math mode. instead, I'd use text mode thoughout, for both function names (e.g., \texttt) and variable names (e.g., \textit). And, if and where necessary, just insert \- discretionary hyphens.

enter image description here

\documentclass{article} % or some other suitable document class
\newcommand\fn[1]{\texttt{#1}} % function name
\newcommand\vn[1]{\textit{#1}} % variable name

\begin{document}
\begin{itemize}
\item A TOSCA requirement definition within a node type definition 
    was encoded with the term \fn{requirement}[\vn{RName}, \vn{RCap}, 
    \vn{RNType}, \vn{RRel}, \fn{occur\-rences}(\hspace{0pt}\vn{ROccLB}, 
    \vn{ROccUB})], where \vn{RName} is an atom for the name of the 
    requirement, \vn{RCap} is an atom for the required capability, 
    \vn{RNType} is an atom for the type of nodes admitted as a target 
    (including subtypes), \vn{RRel} is an atom representing the relationship 
    underlying the requirement, and \vn{ROccLB} and \vn{ROccUB} are 
    respectively lower and upper bound for the number of occurrences 
    of the requirement, \vn{ROccUB} possibly being the atom 
    \fn{unbounded}; \dots
\end{itemize}
\end{document}
1

All that's necessary is to move the spaces out of the \texttt scope:

\documentclass{article}

\addtolength\textwidth{45pt}
\begin{document}

\begin{itemize}

\item A TOSCA requirement definition within a node type definition was
  encoded with the term \texttt{requirement(}$RName$\texttt{,}
  $RCap$\texttt{,} $RNType$\texttt{,} $RRel$\texttt{,}
  \texttt{occurrences(}$ROccLB$\texttt{,} $ROccUB$\texttt{))}, where $RName$
  is an atom for the name of the requirement, $RCap$ is an atom for
  the required capability, $RNType$ is an atom for the type of nodes
  admitted as a target (including subtypes), $RRel$ is an atom
  representing the relationship underlying the requirement, and
  $ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
  number of occurrences of the requirement, $ROccUB$ possibly being
  the atom \texttt{unbounded};

\end{itemize}
\end{document}

output of example code

Presumably the \texttt spaces are fixed width, and with the original coding only two stretchable spaces were allotted to the line containing the fixed-width material and math, which is not nearly enough to allow reasonable justification. Observe that the lines in the paragraph are broken differently when the spaces are removed from the scope of \texttt.

Addendum

The other answers are correct regarding the coding of names. Those names now coded as math should really be coded as explicitly italic. If they will ordinarily appear in math environments, they should be coded as (for example) $\mathit{RName}$ rather than $RName$. They will look much better, since they are words, not strings of variables multiplying one another, which is the usual treatment of letters in math.

0

If you use \mathit so the text is a bit mmore compressed (and readable) and allow the space after a comma in math some flexibility then it (almost) fits on one line without breaking, see thethird item below.

enter image description here

\documentclass{article}

\addtolength\textwidth{45pt}
\begin{document}

\begin{itemize}
    

\item A TOSCA requirement definition within a node type definition was
  encoded with the term \texttt{requirement(}$RName$\texttt{,
  }$RCap$\texttt{, }$RNType$\texttt{, }$RRel$\texttt{,
    occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
  is an atom for the name of the requirement, $RCap$ is an atom for
  the required capability, $RNType$ is an atom for the type of nodes
  admitted as a target (including subtypes), $RRel$ is an atom
  representing the relationship underlying the requirement, and
  $ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
  number of occurrences of the requirement, $ROccUB$ possibly being
  the atom \texttt{unbounded};


\item A TOSCA requirement definition within a node type definition was
  encoded with the term \texttt{requirement(}$RName$\texttt{,
  }$RCap$\texttt{, }$RNType$\texttt{, }$RRel$ \texttt{,
    occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
  is an atom for the name of the requirement, $RCap$ is an atom for
  the required capability, $RNType$ is an atom for the type of nodes
  admitted as a target (including subtypes), $RRel$ is an atom
  representing the relationship underlying the requirement, and
  $ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
  number of occurrences of the requirement, $ROccUB$ possibly being
  the atom \texttt{unbounded};

\item \sloppy \thinmuskip=3mu plus 2mu minus 1.5mu A TOSCA requirement definition within a node type definition was
  encoded with the term $\mathtt{requirement}(\mathit{RName},
  \mathit{RCap}, \mathit{RNType}, \mathit{RRel},
    \mathtt{occurrences}(\mathit{ROccLB}, \mathit{ROccUB}))$, where $\mathit{RName}$
  is an atom for the name of the requirement, $\mathit{RCap}$ is an atom for
  the required capability, $\mathit{RNType}$ is an atom for the type of nodes
  admitted as a target (including subtypes), $\mathit{RRel}$ is an atom
  representing the relationship underlying the requirement, and
  $\mathit{ROccLB}$ and $\mathit{ROccUB}$ are respectively lower and upper bound for the
  number of occurrences of the requirement, $\mathit{ROccUB}$ possibly being
  the atom \texttt{unbounded};



\end{itemize}
\end{document}

You must log in to answer this question.

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