LaTeX: optionally apply a second forceful wrapping of long code lines by jfbu · Pull Request #8854 · sphinx-doc/sphinx (original) (raw)

I have added Unicode support for the 'pdflatex' engine as well as a way to customize when forceful algorithm is triggered. In particular it is possible to have all codelines be systematically hard-wrapped at the available width, if desired.

Now, the output looks like this (I removed letters/digits to change length, so examples are only typographical):

Capture d’écran 2021-02-09 à 11 31 00

In the above I added some non-ascii letters, to check with 'pdflatex' engine. I used

latex_elements = {
    'fontenc': "\\usepackage[X2,LGR,T1]{fontenc}",
    'sphinxsetup': "verbatimforcewraps",
}

to allow Greek and Cyrillic. As the font changes, the character width also, and as a result, we see a letter sticking a bit in margin, but this is exceptional. If we typeset the same using Unicode engine, all is exactly aligned:

Capture d’écran 2021-02-09 à 11 31 43

and I used for this

latex_engine = 'xelatex'

latex_elements = {
#    'fontenc': "\\usepackage[X2,LGR,T1]{fontenc}",
    'sphinxsetup': "verbatimforcewraps",
}

Even with 'pdflatex' all will be aligned with non-ascii letters not from Greek or Cyrillic alphabets which trigger a font substitution.

To hard-wrap all code-blocks at the maximal width:

latex_elements = {
    'sphinxsetup': "verbatimforcewraps, verbatimmaxunderfull=0",
}