LaTeX 文件的全域換行符

LaTeX 文件的全域換行符

我有斷線問題。我編寫了一個工具來產生包含長行(例如 URL 或路徑)的報告。在我產生的 PDF 中,這些行應該被換行。此外,包裝應該自動完成。我知道我可以插入手動包裝。但我需要一個全球的方法(沒有圍繞長行的函數),例如規則或在行結束時全域強制換行。

我已經嘗試過\sloppy並且microtype打包了。但沒有成功。

為了說明我的問題,我做了一個簡單的 LaTeX 範例:

\documentclass{article}

\usepackage{microtype}
\usepackage{ragged2e}
\usepackage[hyphens]{url}
\usepackage{path}

\begin{document}

\specialpathdelimiterstrue

AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash AAAA\textbackslash 

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

http://aaaaaaaaaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
\end{document}

所有三行都應在行/頁面寬度的末尾換行。

有沒有解決方案?我已經搜尋了幾天尋找解決方案..

答案1

我猜您不想為每一行使用宏,因為您的行是自動生成的。但由於您可能會使用\sloppy,因此所有線路周圍的環境可能沒問題。

那麼一個可能的想法是掃描環境的內容並在字元之間添加任意的中斷。

下面的程式碼定義了一個環境wraplines,​​其中所有行都在行尾換行。

\begin{wraplines}
% text
\end{wraplines}

環境採用可選的連字符,該字符實際上可以是任意受限的水平模式材料:-, $\rightarrow$, ...

\begin{wraplines}[-]
% text
\end{wraplines}

此程式碼假設環境中僅出現文字。然而,文本可能包含多個段落。

\documentclass{article}

\makeatletter
\newenvironment{wraplines}[1][]{%
  % encapsulate hyphenation character in a \hbox so that
  % it may be arbitrary restricted horizontal mode material e.g $\rightarrow$
  \def\@wrapdiscr{\discretionary{\hbox{#1}}{}{}}%
  \@wraplines
}{}
\newcommand\@wraplines{%
  \@ifnextchar\end\relax{%
    \@ifnextchar\par{%
      \par\expandafter\@wraplines\@gobble
    }%
    \@wraplines@aux
  }%
}
\def\@wraplines@aux#1 {\x@wraplines@aux#1\@nnil}
\newcommand*\x@wraplines@aux[1]{#1\y@wraplines@aux}
\newcommand*\y@wraplines@aux[1]{%
  \ifx#1\@nnil
    \space
    \expandafter\@wraplines
  \else
    \@wrapdiscr#1%
    \expandafter\y@wraplines@aux
  \fi
}
\makeatother

\begin{document}
\begin{wraplines}
\end{wraplines}

\noindent\verb|\begin{wraplines} ... \end{wraplines}|

\begin{wraplines}
Xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{wraplines}

\bigskip

\noindent\verb|\begin{wraplines}[-] ... \end{wraplines}|

\begin{wraplines}[-]
Xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{wraplines}

\bigskip

\noindent\verb|\begin{wraplines}[$\rightarrow$] ... \end{wraplines}|

\begin{wraplines}[$\rightarrow$]
Xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{wraplines}

\end{document}

包裝.png

相關內容