如何防止使用两个连字符进行自动换行?

如何防止使用两个连字符进行自动换行?

我有以下 markdown 文件演示了该问题(至少在我的环境中):

---
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
headertext: 
headercolor: 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.

上面的代码可能可以稍微缩短一点,但确实说明了这个问题。 被--pid包裹在第一个和第二个连字符之间。我不希望它在第一个连字符之前被包裹。

我使用 pandoc 生成 LaTeX 文件,然后使用 pdflatex 处理该文件生成 PDF 文件。

LaTeX 文件太大,无法在此处放置,但文件主体包含上述内容的部分如下(我将标题页、目录、故意留空的页和修订表保留在下面):

\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}

我的 template.latex 文件中有以下定义\texttt,这是防止长命令自动换行所必需的:

\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
}

我希望能够修改上述\texttt定义来获得我需要的内容,而不必编辑源文件或来自 pandoc 的 LaTeX 文件。

** 更新 **

下面是我能想到的最简单的 LaTeX 示例,它展示了这个问题:

\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},
    colorlinks=true,
    linkcolor=blue,
    citecolor=blue,
    urlcolor=blue,
    breaklinks=true}
\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
\hypersetup{colorlinks=true,linkcolor=blue}

\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}

我希望这有帮助。

答案1

由于您已经对参数进行了替换,因此您可以将其扩展为替换-\/-\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{\ }{~}%
  \tl_replace_all:Nnn\l_jdhao_hlx_tl{-\/-}{\mbox{-\/-}}% added
  \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}

更改文本中的所有惩罚等是没有意义的:设置是段落值。

相关内容