問題

問題

最初我在另一個問題上解決了這個合理性問題如何使用 `\everypar` 理由聲明?,但是現在我注意到一個新問題,我也希望自動完成。

透過編寫這個乳膠程式碼,我正確地得到了我想要的行為:

% proposal.tex
% Based on http://www.latextemplates.com/template/simple-sectioned-essay
\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[brazil]{babel}

\usepackage{hyphsubst}
\usepackage{mathptmx}

\begin{document}

\section{Riscos}

\newbox\linebox \newbox\snapbox
\def\eatlines{
  \setbox\linebox\lastbox % check the last line
  \ifvoid\linebox
  \else % if it’s not empty
    \unskip\unpenalty % take whatever is
    {\eatlines} % above it;
    \setbox\snapbox\hbox{\unhcopy\linebox}
    \ifdim\wd\snapbox<.98\wd\linebox
       \box\snapbox % take the one or the other,
    \else \box\linebox \fi
  \fi}

\everypar={\setbox0=\lastbox \par
   \vbox\bgroup \everypar={}\def\par{\endgraf\eatlines\egroup}}


    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and raggedrightddddd setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

    \medskip
    Second paragraph.

\end{document}

根據使用的給定因素,產生正確縮排的 PDF .98

在此輸入影像描述

但是,如果行中的單字太大,則乳膠會Overfull \hbox (133.24454pt too wide) in paragraph at lines在輸入時拋出錯誤:

    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and raggedrightdddddddddddddddddddddddddddddddddddddddddddddddddddddddddd 
    setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

    \medskip
    Second paragraph.

產生輸出:

在此輸入影像描述


問題

我希望乳膠自動將單字raggedrightdddddddddddddddddddddddddddddddddddddddddddddddddddddddddd分成新行,而不是讓它超出螢幕/文件。

我知道我可以使用以下解決方案將長單字推入新行,因此該單字raggedrightdddddddddddddddddddddddddddddddddddddddddddddddddddddddddd將換成新行:

% Allow to push long words on new lines when they do not fit entirely on the current line.
\newcommand\lword[1]{\leavevmode\nobreak\hskip0pt plus\linewidth\penalty50\hskip0pt plus-\linewidth\nobreak{#1}}

    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and \lword{raggedrightdddddddddddddddddddddddddddddddddddddddddddddddddddddddddd}
    setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

    \medskip
    Second paragraph.

產生以下文件:

在此輸入影像描述

現在,還有另一個詞突破了頁面限制。因此,解決辦法就是再次使用已經失控的字\lword{that}that

所以這是一項非常煩人的工作來解決我的乳膠文件修復問題。我希望 Latex 的目的是讓我擔心文件內容,而不是文件美觀。

如何正確製作乳膠並自動將長單字推入新行,而不是繞過文件放置\lword{...}


更新1

@大衛卡萊爾我有一個新問題,使用這個文件:

% proposal.tex
% Based on http://www.latextemplates.com/template/simple-sectioned-essay
\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[brazil]{babel}

\usepackage{hyphsubst}
\usepackage{mathptmx}

\begin{document}

\section{Riscos}

\newbox\linebox \newbox\snapbox
\def\eatlines{
  \setbox\linebox\lastbox % check the last line
  \ifvoid\linebox
  \else % if it’s not empty
    \unskip\unpenalty % take whatever is
    {\eatlines} % above it;
    \setbox\snapbox\hbox{\unhcopy\linebox}
    \ifdim\wd\snapbox<.98\wd\linebox
       \box\snapbox % take the one or the other,
    \else \box\linebox \fi
  \fi}

\everypar={\setbox0=\lastbox \par
   \vbox\bgroup \everypar={}\def\par{\endgraf\eatlines\egroup}}

\noindent X\dotfill X

\sloppy
\rightskip 0pt plus 1pt
\emergencystretch\textwidth
\hyphenpenalty=10000
\parskip\baselineskip

    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and raggedrightdddddddddddddddddddddddddddddddddddddddddddd setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

    \medskip
    Second paragraph.

\end{document}

我有一個額外的洞,它不應該存在:

在此輸入影像描述

第二行的洞是由於長詞被推入而預料到的。然而,第一行的洞是預料之外的。

最後的結果應該是這樣的:

在此輸入影像描述

可以使用以下命令建立前一個映像\lword{raggedrightdddddddddddddddddddddddddddddddddddddddddddd},例如:

% proposal.tex
% Based on http://www.latextemplates.com/template/simple-sectioned-essay
\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[brazil]{babel}

\usepackage{hyphsubst}
\usepackage{mathptmx}

\begin{document}

\section{Riscos}

\newbox\linebox \newbox\snapbox
\def\eatlines{
  \setbox\linebox\lastbox % check the last line
  \ifvoid\linebox
  \else % if it’s not empty
    \unskip\unpenalty % take whatever is
    {\eatlines} % above it;
    \setbox\snapbox\hbox{\unhcopy\linebox}
    \ifdim\wd\snapbox<.98\wd\linebox
       \box\snapbox % take the one or the other,
    \else \box\linebox \fi
  \fi}

\everypar={\setbox0=\lastbox \par
   \vbox\bgroup \everypar={}\def\par{\endgraf\eatlines\egroup}}

\newcommand\lword[1]{\leavevmode\nobreak\hskip0pt plus\linewidth\penalty50\hskip0pt plus-\linewidth\nobreak{#1}}

    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and \lword{raggedrightdddddddddddddddddddddddddddddddddddddddddddd} setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

    \medskip
    Second paragraph.

\end{document}

更新2

問題是文字寫作的自動化。通常這種情況發生在路徑上,但這是一個乳膠問題,允許單字越界。因此,我想要的只是解決它。解決這個長單字問題的第一個乳膠工具是連字符。然而我不喜歡他們。此外,我更喜歡將單字放在下一行,如下例所示:https://i.stack.imgur.com/f6Bes.png,對我來說,這是一個直接的解決方案。 Latex 絕不允許單字超出頁面限制。嘗試做微軟Word,它不會允許。相反,它會將單字放到下一行。

我想要行對齊,除了一些包含長單字或由於對齊而過於稀疏的特定行。對於大多數行,對齊效果很好,除了提到的情況之外。

Microsoft Word 是這樣處理的:

在此輸入影像描述

雖然長字之前的行非常合理,但它不允許長字超出行限制。

答案1

假設具體問題更像是“我需要明智地列印長文件路徑”,那麼這個怎麼樣?

在此輸入影像描述

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[a4paper, margin=2cm]{geometry}

% https://tex.stackexchange.com/a/10401
\usepackage[hyphens]{url}
\expandafter\def\expandafter\UrlBreaks\expandafter{\UrlBreaks%  save the current one
  \do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
  \do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
  \do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
  \do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
  \do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
  \do\Y\do\Z}

\begin{document}

\section{Riscos}

Original bad breaks, Assim após ativar os testes, basta abrir o arquivo
ArtificialIntelligence/AnswersGuessAiGame/players.py, encontrar a classe ...
Tests logo do final do arquivo e escolher quais dos testes se quer executar.

Option 1, rewrite the paragraph to avoid bad breaks.
Assim após ativar os testes, basta abrir o arquivo
ArtificialIntelligence/AnswersGuessAiGame/players.py, encontrar a classe ...
Tests logo do final do arquivo e escolher quais dos testes se quer executar.

Option 2, use the \verb|\path| command from the \verb|url| package, and allow
URLs to break after any character.
Assim após ativar os testes, basta abrir o arquivo
\path{ArtificialIntelligence/AnswersGuessAiGame/players.py}, encontrar a classe ...
Tests logo do final do arquivo e escolher quais dos testes se quer executar.

\end{document}

相關內容