是否可以使用 \justify (来自先前这个问题) 与 \VerbatimInput?
\begin{filecontents*}{\jobname.txt}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\end{filecontents*}
\documentclass{article}
\usepackage{lipsum}
\usepackage{fancyvrb}
\newcommand*\justify{%
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
\hyphenchar\font=`\-% allowing hyphenation
}
%--------------------------------------------
% redefine \VerbatimInput
\RecustomVerbatimCommand{\VerbatimInput}{VerbatimInput}%
{fontsize=\footnotesize,
framesep=2em, % separation between frame and text
}
\begin{document}
%\texttt{\justify\lipsum[1]}
\VerbatimInput{\jobname.txt}
\end{document}
答案1
对齐和逐字模式不一致,因为逐字环境通常一次检查一行并将其排版为单行段落,可能会超出行宽。
如果您只是想模拟能够对齐行的高级打字机,您可以更简单地声明\ttfamily
,调整字体尺寸并依靠标准对齐。
最后应关闭调整,以免改变的其他应用程序\ttfamily
。
\begin{filecontents*}{\jobname.txt}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
\end{filecontents*}
\documentclass{article}
\usepackage{lipsum}
\usepackage{alltt}
\newcommand*\justify{%
\edef\restore{%
\fontdimen2\font=\the\fontdimen2\font
\fontdimen3\font=\the\fontdimen3\font
\fontdimen4\font=\the\fontdimen4\font
\fontdimen7\font=\the\fontdimen7\font
\hyphenchar\font=\the\hyphenchar\font
}%
\fontdimen2\font=0.5em % interword space
\fontdimen3\font=0.22222em % interword stretch
\fontdimen4\font=0.11111em % interword shrink
\fontdimen7\font=0.11111em % extra space
\hyphenchar\font=`\- % allowing hyphenation
}
%--------------------------------------------
\newcommand{\ttinput}[1]{%
\par\addvspace{\topsep}
\begingroup
\setlength{\parindent}{0pt}%
\ttfamily
\justify
\input{#1}%
\par
\restore
\endgroup
\addvspace{\topsep}
}
\begin{document}
\ttinput{\jobname.txt}
\end{document}