
\texttt{}
공백이 포함되지 않은 긴 텍스트를 라텍스에서 분리하고 싶습니다 . 현재 텍스트가 페이지 밖으로 흘러나오고 있습니다.
라텍스 문서는 reStructureText 문서에서 생성됩니다(reStructuredText를 사용해야 합니다). 따라서 나는 다음 솔루션을 사용하지 않는 것을 선호합니다.
- 또는
\texttt{}
으로 교체 (누군가 Docutils에서 그렇게 하는 방법을 알려주지 않는 한)\path{}
\url{}
- 삽입
\allowbreak{}
/소프트 하이픈(실행 가능하지만 reStructuredText 문서의 가독성이 손상됨)
texttt 문자열이 깨지는 원인이 되는 전역 구성이 라텍스 문서에 있습니까? 모든 텍스트를 표시하는 인쇄 가능한 문서를 얻는 다른 좋은 방법이 있습니까?
내 문제에 대한 최소한의 예는 다음과 같습니다.
\documentclass[a4paper]{article}
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
\end{document}
"pdflatex a.tex"를 사용하여 PDF를 만들려고 하면 "TranformerException"에서 "TranformerEx"만 표시됩니다.
답변1
egreg의 답변을 훔치는 중url 패키지를 사용하지 않고 \url 하이픈 넣기를 에뮬레이트하는 방법은 무엇입니까?, 그가 재정의한 곳에서 나는 대신에 \url
재정의하기 위해 동일한 재정의로 시작합니다 . egreg의 원래 구현에서는 및 문자 에서 줄 바꿈을 허용했습니다 .\texttt
\url
.
/
[
그러나 다른 중단점 기호를 추가할 수 있습니다. 예를 들어 아래에서는 중단점도 만듭니다 .
\documentclass[a4paper]{article}
\renewcommand{\texttt}[1]{%
\begingroup
\ttfamily
\begingroup\lccode`~=`/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
\begingroup\lccode`~=`[\lowercase{\endgroup\def~}{[\discretionary{}{}{}}%
\begingroup\lccode`~=`.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
\catcode`/=\active\catcode`[=\active\catcode`.=\active
\scantokens{#1\noexpand}%
\endgroup
}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
If an unrecoverable error occurs during the transformation, then a
\texttt{\$GLOBALS['TCA']['tt\_address']['feInterface']['fe\_admin\_fieldList']}
\end{document}
섹션이나 다른 제목 또는 .aux 파일에 기록되고 다시 읽어지는 다른 위치에서 이 솔루션을 사용해야 하는 경우 다음 \renewcommand
으로 바꿔야 합니다 \DeclareRobustCommand
. 자세한 내용은 이 답변을 참조하세요.래핑 \texttt{}를 섹션 및 TOC와 결합 - 잘못된 알파벳 상수
보충
_
Lemdan은 댓글에서 밑줄을 중단점 으로 만드는 방법을 묻습니다(그리고 Joey는 오래 전에 물었습니다). 밑줄은 일반적으로 catcode 8이기 때문에 12로 설정된 \texttt
catcode 대신 사용하는 인수를 흡수해야 합니다 _
. 물론 이렇게 하면 a 내부의 수학 내부에서 첨자를 사용하는 것을 방지할 수 있지만 \texttt
생활하기가 너무 어렵지는 않습니다. 와 함께. 이렇게 하면 에서 밑줄을 이스케이프 처리할 필요도 없어집니다 \texttt
.
\documentclass[a4paper]{article}
\catcode`_=12 %
\renewcommand{\texttt}[1]{%
\begingroup
\ttfamily
\begingroup\lccode`~=`/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
\begingroup\lccode`~=`[\lowercase{\endgroup\def~}{[\discretionary{}{}{}}%
\begingroup\lccode`~=`.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
\begingroup\lccode`~=`_\lowercase{\endgroup\def~}{_\discretionary{}{}{}}%
\catcode`/=\active\catcode`[=\active\catcode`.=\active\catcode`_=\active
\scantokens{#1\noexpand}%
\endgroup
}
\catcode`_=8 %
\usepackage{lipsum}
\begin{document}
\lipsum[4]
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
If an unrecoverable error occurs during the transformation, then a
\texttt{\$GLOBALS_'TCA']['tt_address']['feInterface']['fe_admin_fieldList']}
\end{document}
답변2
Steven의 답변에 따라 내 문서에서는 그림에서 경로와 URL을 표시하는 데 사용했지만 텍스트에서도 작은 코드 조각을 강조 표시하는 데 \texttt
사용했습니다 .\texttt
Steven이 제공한 코드는 내 그림에서 작동하지만 \texttt
기호를 사용하지 않는 일반 텍스트에 대한 명령을 작성할 때 여전히 여백이 오버플로됩니다. 아래 이미지와 같이 \texttt
그림에는 잘 작동하지만 일반 텍스트에는 제대로 작동하지 않습니다.
이 문제를 해결하기 위해 다음 코드를 빌렸습니다.\justify
이 tex.se 게시물에서방금 기존 코드에 추가했습니다.
\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
}
\renewcommand{\texttt}[1]{%
\begingroup
\ttfamily
\begingroup\lccode`~=`/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
\begingroup\lccode`~=`[\lowercase{\endgroup\def~}{[\discretionary{}{}{}}%
\begingroup\lccode`~=`.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
\catcode`/=\active\catcode`[=\active\catcode`.=\active
\justify\scantokens{#1\noexpand}%
\endgroup
}
이는 훨씬 더 나은 출력을 생성하며 다른 장소에서 타자기를 사용하는 경우에 적합합니다.
답변3
서문에서 얼마나 많은 작업을 수행할 의향이 있는지 잘 모르겠지만 다음은 제안 사항입니다.
\documentclass{article}
\begingroup
\catcode`\.=\active
\gdef.{\normalperiod\allowbreak}%
\endgroup
\newcommand\aepath[1]{%%
\bgroup
\let\normalperiod=.%%
\catcode`\.=\active
\everyeof{\noexpand}%%
\endlinechar=-1%%
\ttfamily\scantokens{#1}%%
\egroup}
\let\oldtexttt\texttt
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
\end{document}
귀하의 MWE에서 나는 귀하가 a가 .
발생하는 지점에서 코드를 깨뜨릴 수 있기를 원한다고 가정했습니다. 긴 텍스트가 나올 수 있는 모든 상황에 분리된 이름이 포함되어 있고 문서에서 다른 목적으로 .
필요하지 않다고 가정하면 이것이 해결책이 될 수 있습니다.\texttt
다른 패키지가 활성화되기를 원하지만 다르게 정의될 수 있다는 우려가 있는 경우 .
다음 접근 방식을 취할 수 있습니다.
\documentclass{article}
\begingroup
\catcode`\.=\active
\gdef\redefineperiod{\def.{\normalperiod\allowbreak}}%%
\endgroup
\newcommand\aepath[1]{%%
\bgroup
\let\normalperiod=.%%
\catcode`\.=\active
\redefineperiod
\everyeof{\noexpand}%%
\endlinechar=-1%%
\ttfamily\scantokens{#1}%%
\egroup}
\let\oldtexttt\texttt
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown. Followed
by more text which is just to fill to the ned of the line.
\end{document}
순진하게(예: 이것이 제가 처음에 할 수 있다고 생각했던 것입니다) 시도해 볼 수도 있습니다.
\documentclass{article}
\newcommand\aepath[1]{%%
\bgroup
\let\normalperiod=.%%
\catcode`\.=\active
\def.{\normalperiod\allowbreak}%%
\everyeof{\noexpand}%%
\endlinechar=-1%%
\ttfamily\scantokens{#1}%%
\egroup}
\let\oldtexttt\texttt
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown. Followed
by more text which is just to fill to the ned of the line.
\end{document}
그러나 다음 기간이 \def
이미 토큰화되어 활성화되지 않았기 때문에 이는 실패합니다. 따라서 LaTeX는 누락된 제어 시퀀스에 대한 오류를 발생시킵니다.
업데이트
중단이 발생하는 위치에 대해 특별히 걱정하지 않는 경우 다음과 같은 것을 사용할 수 있습니다.
\documentclass{article}
\makeatletter
\newcommand\aepath[1]{%%
\bgroup
\ttfamily
\ae@path#1\relax\@nil
\egroup}
\def\ae@path#1#2\@nil{%%
\def\ae@continue{}%%
\detokenize{#1}\unskip\penalty\z@
\ifx\relax#2%%
\else
\def\ae@continue{\ae@path#2\@nil}%%
\fi
\ae@continue}
\makeatother
\let\texttt\aepath
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
\end{document}
하지만 이것은 나에게 약간 차선책인 것 같습니다. 중단점이 있어야 할 위치를 결정하고 예제를 따라 .
해당 문자(예: /
, -
등)를 명령 컨텍스트 내에서 활성 문자로 만들고 페널티를 밀수하여 따라오는 중단점을 허용하는 것이 더 나을 것이라고 생각합니다 .
답변4
답변이 늦었지만 답변이 포함된 질문을 게시했습니다.여기, 다시 말 그대로 다음과 같습니다.
\seqsplit을 사용하세요.
\documentclass[9pt,oneside]{amsart}
\usepackage{seqsplit}
\begin{document}
Filler text. Filler text. Filler text. Filler text. \seqsplit{0xcf416c536ec1a19ed1fb89e4ec7ffb3cf73aa413b3aa9b77d60e4fd81a4296ba}
\end{document}