编辑

编辑

编辑

我认为这与链接的“重复”略有不同,因为这里的段落格式为打字机格式,使用\ttfamily而在重复中有

他的文本周围散布着大量打字机字体的“常用词”。

解决方案当然是相似的,但“Heiko Oberdiek”(此处标记为答案)给出了一个很好的工作示例和有关此问题的解释。就我个人而言,我无法理解“重复”问题中建议的代码的哪些部分对于解决我的问题是必不可少的。

原始问题

我最近有一些较大的文本想要放入 \t​​tfamily。

然而,我注意到分词功能并没有真正起作用,并做了一些研究来添加以下几行:

\setlength{\emergencystretch}{2em}
\newcommand{\origttfamily}{}%
\let\origttfamily=\ttfamily%
\renewcommand{\ttfamily}{\origttfamily \hyphenchar\font=`\-}

还在 memoir-class 和 babel-package 中使用英语选项。

这在某种程度上是有帮助的,因为现在发生了一些单词断开和空间拉伸,但最终,大多数段落看起来更像是左对齐而不是两端对齐。并且仍然有一些线条超出了定义的边界。

这是一个最小的例子,包含两个较长的文本段落,一个是纯文本,一个是 ttfamily 格式。

\documentclass[english,11pt,oneside,article,a5]{memoir}
\usepackage[english]{babel}
\usepackage{geometry} 

\setlength{\emergencystretch}{2em}
\newcommand{\origttfamily}{}%
\let\origttfamily=\ttfamily %
\renewcommand{\ttfamily}{\origttfamily \hyphenchar\font=`\-}

\geometry{left=20mm,right=20mm, top=20mm, bottom=50mm}
\OnehalfSpacing
\leftskip3em\rightskip2em

\begin{document}
$>$She didn’t want to spend the time trying to locate them, or try to thin out the operator’s patience for Alison doing whatever. She expects they are already rather sour at her burrowing a tunnel through most of the building’s floors to make that railgun using an enormous amount of jetalium. If she gets a chance later, though, to come back to this place, she’ll put rescuing Loviro on the table. 
\\{}\ttfamily According to the engineer, they are most likely tethers to launch things cheaply into space, given how high they go. Although, Alison does come by close enough to see one to see a revolving restaurant at the top of it, so tossing stuff into space may not be its only function.
\end{document}

我这样使用 ttfamily 是不是出了什么问题?

答案1

这里的问题不是连字符,因为 TeX 找不到合适的位置来连字符。问题在于单词之间的空间缺乏灵活性。这可以通过字体参数添加。或者\spaceskip可以\xspaceskip设置。

\documentclass[english,11pt,oneside,article]{memoir}
\usepackage[english]{babel}
\usepackage{geometry}
\setlength{\emergencystretch}{2em}

\usepackage{letltxmacro}
\LetLtxMacro\origttfamily\ttfamily
\DeclareRobustCommand*{\ttfamily}{%
  \origttfamily
  \hyphenchar\font=`\-\relax
  \fontdimen3\font=.25em\relax
  \fontdimen4\font=.167em\relax
  \fontdimen7\font=.167em\relax
}

\makeatletter
\DeclareRobustCommand\vttfamily{%
  \not@math@alphabet\vttfamily\relax
  \fontfamily{cmvtt}% cmvtt (Computer Modern) or lmvtt (Latin Modern)
  \selectfont
}
\DeclareTextFontCommand{\textvtt}{\vttfamily}
\makeatother

\geometry{left=20mm,right=20mm, top=20mm, bottom=50mm}
\OnehalfSpacing
\leftskip3em\rightskip2em

\begin{document}
$>$She didn’t want to spend the time trying to locate them, or try to thin
out the operator’s patience for Alison doing whatever. She expects they are
already rather sour at her burrowing a tunnel through most of the building’s
floors to make that railgun using an enormous amount of jetalium. If she gets
a chance later, though, to come back to this place, she’ll put rescuing
Loviro on the table.
\\{}\ttfamily According to the engineer, they are most likely tethers to
launch things cheaply into space, given how high they go. Although, Alison
does come by close enough to see one to see a revolving restaurant at the
top of it, so tossing stuff into space may not be its only function.
\\{}\vttfamily According to the engineer, they are most likely tethers to
launch things cheaply into space, given how high they go. Although, Alison
does come by close enough to see one to see a revolving restaurant at the
top of it, so tossing stuff into space may not be its only function.
\end{document}

结果

评论:

  • 为了进行比较:第三部分由可变宽度的打字机字体设置。

  • 正如解释的那样如何在 \texttt 内自动连字符?,字体尺寸的设置是全局的。但这可能不是问题,因为\ttfamily无论如何都是重新定义的。

  • letltxmacro使用包,因为保存通过定义的宏\DeclareRobustCommand比较棘手。

相关内容