Esta questão desenvolveu-se a partirComo lidar com frases lstinline muito longas, como nomes de classes longos?.
Essa questão é sobre quebra de linha dentro de uma \lstinline
frase. Forneci uma resposta que hifeniza automaticamente letras maiúsculas e, em um comentário, percebi que às vezes _
também poderia ser útil ter hifenização automática em sublinhados.
Consegui implementar isso, mas resta uma falha: gostaria de evitar _
a hifenização automática no início do nome (em Python, por exemplo, esta é uma situação comum, pois por convenção, nomes internos começam com um sublinhado (ou dois )).
\documentclass{article}
\usepackage[paperwidth=10cm,paperheight=5cm]{geometry}
\pagestyle{empty}
\usepackage{lstdoc}
\lstMakeShortInline[literate={\_}{\_}{1\discretionary{\_}{}{}}]|
\begin{document}
\textbf{Good line break:} in this paragraph the line break in the
python's variable |a_python_style_name| is good!
\textbf{Bad line break:} the internal variable |_internal_python_name|
is not hyphenated very nicely in this paragraph.
\end{document}
Responder1
Contorne a \discretionary
inserção inserindo outra coisa apenas para começar. Aqui estão algumas opções:
\documentclass{article}
\usepackage[paperwidth=10cm,paperheight=8cm]{geometry}
\pagestyle{empty}
\usepackage{lstdoc}
\lstset{mathescape=true}
\lstMakeShortInline[literate={\_}{\_}{1\discretionary{\_}{}{}} {~}{\_}{1}]|
\newcommand{\preunderscore}{\_}
\begin{document}
\textbf{Good line break:} in this paragraph the line break in the
python's variable |a_python_style_name| is good!
\textbf{Bad line break:} the internal variable |_internal_python_name|\par
|_internal_python_name|
\textbf{Bad line break:} the internal variable |~internal_python_name|\par
|~internal_python_name|
\textbf{Bad line break:} the internal variable |$\preunderscore$internal_python_name|\par
|$\preunderscore$internal_python_name|
\end{document}
Com mathescape
você pode inserir uma macro em vez de um literate
substituto para _
. Alternativamente, use um literate
caractere diferente para o início. Existem diferenças no espaçamento.