我有一个要求,即某些单词应该在正文中单独格式化。为此,我编写了一个新命令
\newcommand{\concept}[1]{\textcolor{gray}{\texttt{#1}}}
我不希望命令中写入的单词\concept{}
被连字符连接。它们可以推到下一行,但不能被连字符连接。我在这里有什么选择?
编辑 1:在 MWE 中添加了显示连字符的包\texttt
。我不需要在一段话中写那么多条目,只需显示它是如何破坏内部tt
环境的。使用 进行编译xelatex
。
\documentclass[12pt,a4paper]{article}
\usepackage{fontspec}
\usepackage{libertine}
\setmonofont{Latin Modern Mono Light}
\usepackage{geometry}
\geometry{a4paper, textwidth=6.in, textheight=9.25in, marginparsep=7pt, marginparwidth=.6in}
\usepackage[svgnames]{xcolor}
\renewcommand{\baselinestretch}{1.3}
\newcommand{\concept}[1]{\textcolor{gray}{\texttt{(#1)}}}
\begin{document}
Each step in the development of the \concept{bourgeoisie} was accompanied by a corresponding \concept{political} advance of that class. An \concept{oppressed} class under the sway of the feudal nobility, an armed and self-governing association in the \concept{medieval} \concept{commune}: here independent urban republic (as in Italy and Germany); there taxable “third estate” of the \concept{monarchy} (as in France); afterwards, in the period of manufacturing proper, serving either the \concept{semi-feudal} or the absolute monarchy as a counterpoise against the \concept{nobility}, and, in fact, cornerstone of the great monarchies in general, the \concept{bourgeoisie} has at last, since the establishment of Modern Industry and of the world market, conquered for itself, in the \concept{modern} representative \concept{State}, exclusive political sway. The executive of the modern state is but a committee for managing the common affairs of the whole bourgeoisie.
\end{document}
答案1
您应该声明等宽字体的文本不应该使用连字符,fontspec
默认情况下不会这样做:
\documentclass[12pt,a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
textwidth=6.in,
textheight=9.25in,
marginparsep=7pt,
marginparwidth=.6in
}
\usepackage[svgnames]{xcolor}
\usepackage{libertine}
\setmonofont{Latin Modern Mono Light}[HyphenChar=None]
\renewcommand{\baselinestretch}{1.3}
\newcommand{\concept}[1]{\textcolor{gray}{\texttt{(#1)}}}
\begin{document}
Each step in the development of the \concept{bourgeoisie} was accompanied
by a corresponding \concept{political} advance of that class. An
\concept{oppressed} class under the sway of the feudal nobility, an armed
and self-governing association in the \concept{medieval} \concept{commune}:
here independent urban republic (as in Italy and Germany); there taxable
“third estate” of the \concept{monarchy} (as in France); afterwards, in the
period of manufacturing proper, serving either the \concept{semi-feudal} or
the absolute monarchy as a counterpoise against the \concept{nobility}, and,
in fact, cornerstone of the great monarchies in general, the
\concept{bourgeoisie} has at last, since the establishment of Modern Industry
and of the world market, conquered for itself, in the \concept{modern}
representative \concept{State}, exclusive political sway. The executive of
the modern state is but a committee for managing the common affairs of the
whole bourgeoisie.
\end{document}
但是,这会导致许多行过满;此类段落应排版为\sloppy
;使用sloppypar
来限制行为。使用microtype
可减少丑陋。
\documentclass[12pt,a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
textwidth=6.in,
textheight=9.25in,
marginparsep=7pt,
marginparwidth=.6in
}
\usepackage[svgnames]{xcolor}
\usepackage{microtype}
\usepackage{libertine}
\setmonofont{Latin Modern Mono Light}[HyphenChar=None]
\renewcommand{\baselinestretch}{1.3}
\newcommand{\concept}[1]{\textcolor{gray}{\texttt{(#1)}}}
\begin{document}
\begin{sloppypar}
Each step in the development of the \concept{bourgeoisie} was accompanied
by a corresponding \concept{political} advance of that class. An
\concept{oppressed} class under the sway of the feudal nobility, an armed
and self-governing association in the \concept{medieval} \concept{commune}:
here independent urban republic (as in Italy and Germany); there taxable
“third estate” of the \concept{monarchy} (as in France); afterwards, in the
period of manufacturing proper, serving either the \concept{semi-feudal} or
the absolute monarchy as a counterpoise against the \concept{nobility}, and,
in fact, cornerstone of the great monarchies in general, the
\concept{bourgeoisie} has at last, since the establishment of Modern Industry
and of the world market, conquered for itself, in the \concept{modern}
representative \concept{State}, exclusive political sway. The executive of
the modern state is but a committee for managing the common affairs of the
whole bourgeoisie.
\end{sloppypar}
\end{document}
答案2
如果texttt
文本仍然带连字符(即使不应该带连字符)或者当您有类似的任务时,您可以尝试mbox
它,即:
\newcommand{\concept}[1]{\mbox{\textcolor{gray}{\texttt{#1}}}}
一个小例子:
\documentclass{article}
\usepackage{xcolor}
\newcommand{\concept}[1]{\mbox{\textcolor{gray}{\texttt{#1}}}}
\begin{document}
A pre-test question about how to find distance from the Earth to the Sun \concept{(collaboration)}\concept{(prior knowledge)}
\end{document}
结果