質問

質問

当初私はこの正当化問題を他の質問で解決しました`\everypar` 正当化ステートメントはどのように使用できますか?しかし、今、私は新たな問題に気付いており、これも自動的に実行したいと考えています。

この LaTeX コードを記述することで、希望する動作を正しく得ることができました。

% 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}

.98使用される係数を指定すると、正しくインデントされた次の PDF が生成されます。

ここに画像の説明を入力してください

ただし、行に大きすぎる単語がある場合、Overfull \hbox (133.24454pt too wide) in paragraph at lines入力時に LaTeX はエラーをスローします。

    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単語が画面/ドキュメントの外に出ないように、LaTeX で単語を自動的に新しい行に分割するようにしたいと思います。

私は次の解決策を使用できることを知っています長い単語を新しい行に挿入するなので、単語は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 ドキュメントの修正を回避するための非常に面倒な作業です。LaTeX の目的は、ドキュメントの見た目ではなく、ドキュメントの内容について心配できるようにすることです。

ドキュメントを迂回するのではなく、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}

存在しないはずの余分な穴ができました:

ここに画像の説明を入力してください

長いワードがプッシュされたため、2 行目のホールは予想されます。ただし、1 行目のホールは予想されません。

最終的には次のようになります。

ここに画像の説明を入力してください

この以前のイメージは、次のコマンドを使用して作成できます\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

問題は、テキストの書き込みの自動化です。通常、これはパスが原因で発生しますが、これは単語が行を越える可能性がある LaTeX の問題です。したがって、私がしたいのは、これを修正することです。この長い単語の問題に対する最初の LaTeX ツールはハイフンです。しかし、私はハイフンが好きではありません。さらに、次の例のように、単語を次の行に配置することを好みます。https://i.stack.imgur.com/f6Bes.png私にとっては、これは簡単な解決策です。Latex では、単語がページ制限を超えることは許可されません。Microsoft 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}

関連情報