# How to prevent word wrapping with 2 hyphens?

I have the following markdown file that demonstrates the issue (at least in my environment):

---
title: TEST
subtitle: Minimum Working Example
version: 1.0 rev0
document: TEST-MWE
date: 27 December 2018
preparername: Me
preparerstreet: Here
preparercity: Someplace
preparerstate: US
preparerzip: 11111
footertext:
footercolor: green
toc-depth: 3
graphics: yes
geometry: margin=1in
revisions: |
Table: Revisions to Document

| **Date** | **Document Version** | **Changes Made** |
|:---:|:---:|--------------------------------|
|27 Dec 2018|1.0 rev0|Software Version 1.0 - MWE Only|
---

# Example
An example of the double-hyphen wrapping issue.

## Process
See below.

### List Process
The --all flag can be used to list all processes that have been started. The --pid and --uniqueid
arguments can be used to display information about a specific pid or unique id, respectively. If
called with the --verbose flag, the command will display the complete output of the process, as well
as the Exit Code, Run Time, and other process information, if available.


The above could probably be shortened a bit, but does demonstrate the issue. The --pid is wrapped between the first and second hyphens. I don't want it to be wrapped before the first hyphen.

I use pandoc to generate a LaTeX file, which is then processed by pdflatex to generate a PDF file.

The LaTeX file is too large to put here, but the section of the file that has the above for the document body is as follows (I left the title page, table of contents, intentional blank page, and revision table out of the below):

\begin{document}

%% DOCUMENT BODY
\RaggedRight
\hypertarget{example}
\section{Example}\label{example}

An example of the double-hyphen wrapping issue.

\hypertarget{process}
\subsection{Process}\label{process}

See below.

\hypertarget{list-process}
\subsubsection{List Process}\label{list-process}

The \texttt{-\/-all} flag can be used to list all processes that have
been started. The \texttt{-\/-pid} and
\texttt{-\/-uniqueid} arguments can be used to display information
about a specific pid or unique id, respectively. If
called with the \texttt{-\/-verbose} flag, the command will display the
complete output of the process, as well as the Exit Code, Run Time, and
other process information, if available.

\end{document}


I have the following definition in my template.latex file for the \texttt, which is needed to prevent word wrapping for long commands:

\let\oldTexttt\texttt
\renewcommand{\texttt}[1]{%
\hyphenpenalty=10000
\exhyphenpenalty=10000
\setlength{\emergencystretch}{6em}
\setlhcolor{codegray}%
{\ttfamily\hl{#1}}%
\setlength{\emergencystretch}{3em}
\exhyphenpenalty=50
\hyphenpenalty=50
}


I'd like to be able to modify the above \texttt definition to get what I need, rather than having to edit either the source files or the LaTeX file from pandoc.

** Update **

Here is the simplest LaTeX example I could come up with that exhibits the problem:

\documentclass[12pt,]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{mathptmx} % makes Time New Roman the default font
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in vebatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\PassOptionsToPackage{hyphens}{url} % url is loaded by hyperref
\usepackage[unicode=true]{hyperref}
\PassOptionsToPackage{usenames,dvipsnames}{color} % color is loaded by hyperref
\hypersetup{
pdftitle={TEST},
citecolor=blue,
urlcolor=blue,
\urlstyle{same} % don't use monospace font for urls
\usepackage[margin=1in]{geometry}
\usepackage{listings}
\usepackage{longtable,booktabs}
% Fix footnotes in tables (requires footnote pacakge)
\IfFileExists{footnote.sty}{\usepackage{footnote}\makesavenoteenv{long table}}{}
% Fix gaps in table rulings
\aboverulesep=0ex
\belowrulesep=0ex
\renewcommand{\arraystretch}{1.2}
% Make rulings on tables 1 pixel
\setlength\heavyrulewidth{0.001em}
\setlength\arrayrulewidth{0.001em}
\renewcommand*{\midrule}{}%
\renewcommand*{\bottomrule}{}%
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight \else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}

\usepackage{parskip}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{soul}

\pagestyle{fancy}

\usepackage{caption}
\usepackage{float}

\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

\definecolor{codegray}{HTML}{F0F0F0}
\definecolor{framegray}{HTML}{C0C0C0}
\sethlcolor{graycode}

% unbreak escaped space character in inline codeblocks
\usepackage{xparse}
\usepackage{ragged2e}

\let\hlORIG\hl

\ExplSyntaxOn
\tl_new:N \l_jdhao_hlx_tl
\RenewDocumentCommand\hl{m}{%
\tl_set:Nn\l_jdhao_hlx_tl{#1}%
\tl_replace_all:Nnn\l_jdhao_hlx_tl{\ }{~}%
\exp_args:NV\hlORIG\l_jdhao_hlx_tl}%
\ExplSyntaxOff

% override the inline coding style to show gray highlight box
\let\oldTexttt\texttt
\renewcommand{\texttt}[1]{%
\hyphenpenalty=10000
\exhyphenpenalty=10000
\setlength{\emergencystretch}{6em}
\sethlcolor{codegray}%
{\ttfamily\hl{#1}}%
\setlength{\emergencystretch}{3em}
\exhyphenpenalty=50
\hyphenpenalty=50
}

\usepackage{hyperref} % enables formatting of hyperlinks == must be declared before start of doc

\begin{document}
\renewcommand*\thesection{\arabic{section}.0}
\renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}}

\section{Example}

An example of the double-hyphen wrapping issue.

\subsection{Process}

See below.

\subsubsection{List Process}

The \texttt{-\/-all} flag can be used to list all processes that have
been started. The \texttt{-\/-pid} and \texttt{-\/-uniqueid} arguments
can be used to display information about a specific pid or unique id,
respectively. If called with the \texttt{-\/-verbose} flag, the command
will display the complete output of the process, as well as the Exit
Code, Run Time, and other process information, if available.

\end{document}


I hope this helps.

• BTW: I know that there is a better way to deal with the hypenation penalties using groups, but I'm not sure if I should use \begingroup...\endgroup or \bgroup...\egroup. So, some guidance here would be helpful. – JonBelanger Dec 27 '18 at 16:29
• Make an effort and create a complete (latex) example which demonstrates your issue. – Ulrike Fischer Dec 27 '18 at 16:50
• Since I am using pandoc to generate the LaTeX file, the resulting file is 400+ lines long. Too, long to put it in here. Plus the template.latex file is 700+ lines itself. The MD file, all 38 lines of it is the first code example and is complete. – JonBelanger Dec 27 '18 at 16:56
• Well then shorten the latex file. It shouldn't be so difficult to extract the relevant preamble commands and a paragraph. I won't investigate if I don't have enough info. – Ulrike Fischer Dec 27 '18 at 17:01
• I cut it down as much as I could. It is 145 lines long and demonstrates the problem when processing with pdflatex. – JonBelanger Dec 27 '18 at 20:43

As you already doing a replace on the argument, you could expand it to replace the -\/- by \mbox{-\/-}:

\documentclass[12pt,]{article}
\usepackage{lmodern}
\usepackage{mathptmx} % makes Time New Roman the default font
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% use upquote if available, for straight quotes in vebatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion,expansion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\usepackage{listings}
\setlength{\emergencystretch}{3em} % prevent overfull lines

\usepackage{parskip}
\usepackage{xcolor}
\usepackage{soul}

\definecolor{codegray}{HTML}{F0F0F0}
\definecolor{framegray}{HTML}{C0C0C0}
\sethlcolor{graycode}

% unbreak escaped space character in inline codeblocks
\usepackage{xparse}
\usepackage{ragged2e}

\let\hlORIG\hl

\ExplSyntaxOn
\tl_new:N \l_jdhao_hlx_tl
\RenewDocumentCommand\hl{m}{%
\tl_set:Nn\l_jdhao_hlx_tl{#1}%
\tl_replace_all:Nnn\l_jdhao_hlx_tl{\ }{~}%
\exp_args:NV\hlORIG\l_jdhao_hlx_tl}%
\ExplSyntaxOff

% override the inline coding style to show gray highlight box
\let\oldTexttt\texttt
\renewcommand{\texttt}[1]{%
\sethlcolor{codegray}%
{\ttfamily\hl{#1}}%
}

\begin{document}
The \texttt{-\/-all} flag can be used to list all processes that have
been started. The \texttt{-\/-pid} and   \texttt{-\/-uniqueid} arguments
can be used to display information about a specific pid or unique id,
respectively. If called with the \texttt{-\/-verbose} flag, the command
will display the complete output of the process, as well as the Exit
Code, Run Time, and other process information, if available.

\end{document}


It doesn't make sense to change all the penalties etc in texttt: the settings are paragraph values.

• As for your comment, I think with the indicated change, I can simplify that macro quite a bit. – JonBelanger Dec 28 '18 at 13:43