New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeX: optional rounded corners for framing of code-blocks #10639
Conversation
The background colour changing seems surprising due to 'just' changing the rounded corner setting -- is this part necessary? A |
It is not necessary indeed. What is done is that if user decides for rounded corners the background color default will be changed from white to light gray. Why did I do that? because I copied over the default color (light gray inside, darkish gray on border) from LaTeX package tcolorbox... I have no strong opinion, I can revert it to keep default white of course. edit: and actually that would remove some a bit messy coding for this change of default, as the option handler of LaTeX sphinx is not very sophisticated. I mean it is based on robust kvoptions and does not have all the bells and whistles of things such as pgfkeys, l3keys, etc... |
Thanks @AA-Turner I have now removed this colour change which was indeed not a good idea (and caused some LaTeX coding complications). |
Memo: the reason the new code is presented as a "package" is a bit subtle; it is because its loading will a priori not happen while LaTeX does edit: also I called the file "sphinxpackageboxes.sty" and not "sphinxlatexboxes.sty" with the vague idea that it may grow in future... The hardest part is done, and is combined with the recent refactorings in "sphinxlatexliterals.sty" for subtle color issues; I experimented that "tcolorbox" has the similar color issues at page breaks with its "breakable" boxes, which they solve via a " Anyway, at some point we should probably convert all files |
Via a new configuration verbatimradius of 'sphinxsetup', which defaults to 0pt. If this dimension is non zero, the LaTeX package pict2e will be loaded to help construct frames with rounded corners for code-blocks. And if the LaTeX package pict2e was not found, a LaTeX warning is issued during PDF build.
I completely forgot that Anyway, pre-expansion was not needed. Updated and tested ok on a system with TeXLive 2013. |
There was no need for pre-expansion via \expanded and the latter was not available prior to TL2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
Thanks @tk0miya and @AA-Turner for comments! I merge this now because I have time til Friday and plan to make a PR extending this with significant enhancements of LaTeX PDF rendering of display boxes (topic, admonitions and litteral-blocks like here):
In short, try to obtain almost HTML-like styling possibilities |
@jfbu -- what is our minimum supported TeXLive? I believe that the TUG/TeXLive maintainers only support the latest version -- would it make sense for us to adopt a policy of e.g. current & immediate previous TeXLive? (e.g. currently 2022 and 2021.) That might allow for code simplifications, using the new programming layer in the kernel, etc? But I am not a LaTeX expert by any means! A |
Hi A @AA-Turner, well your question made me realize I have for some time now not followed up closely on our CI policy regarding LaTeX, and it seems we are not testing actual LaTeX runs as far as I can tell from, e.g., https://github.com/sphinx-doc/sphinx/runs/7220623547?check_suite_focus=true#step:8:632
I remember in the past that I was more knowledgeable. We do have this in our documentation:
And this was indeed true perhaps 2 or 3 years ago, now I don't know. Back to your question:
That would definitely simplify maintenance but is way too drastic... The majority of Sphinx users are probably on Linux distros whose TeX distributions notoriously lag behind current TeX-Live by many years. Or at least did so in the past. You can see the above which indicates we always allowed at least 5 years back TeX installations.
TL:DR;: For time being I think it is better that we do not use in Sphinx LaTeX code the L3 programming layer and stick to old coding style. Update: I realize I focused on one way of understanding your question. Another way is to use packages which require recent LaTeX changes. Perhaps in the area of "tables" is where I see potential for this ; some years ago there were naturally queries for Sphinx to use "tabu" package which was a very innovative and widely used; but it became unmaintained with unsolved bugs so it is fortunate we did not use it. Some new packages have appeared which require recent LaTeX. However, Sphinx already has some structure to solve problems there for which there is no equivalent in the world of LaTeX packages: I am alluding to the merged cells of grid-tables... I don't see how to guarantee backwards compatibility if you jump on even formula one level racing package using fully modern LaTeX... OK, I have made my reply even longer, but at least I did catch some sleep in-between... (lengthy musings) This is complicated topic. After a long period of quasi immobility, the LaTeX kernel has evolved at a continuous rate since about 2015. In particular issues related to Unicode in filenames or labels, or multiple dots in filenames of graphics files have evolved positively. Their main preoccupations at this time seem to revolve around PDF tagging (for which some Adobe funding was granted) and integration into the kernel of hyperref. This will take many years. The programming layer encapsulates expert knowledge of core TeX tokenization and box model into some logically structured conventions and vocabulary which allow to package authors to achieve logically complicated tasks without in fact needing to have this expert knowledge of core TeX. But I don't see how the LaTeX user base, which at 99,9% never understood much to TeX macros (for example most people using LaTeX never really understand space tokens ; even authors of very big packages do not necessarily understand it well), would suddenly become fluent in things such as: \par ->\scan_stop: \mode_if_horizontal:TF {\mode_if_inner:F {\tex_unskip:D \hoo
k_use:n {para/end}\@kernel@after@para@end \mode_if_horizontal:TF {\if_int_compa
re:w 11=\tex_lastnodetype:D \tex_hskip:D \c_zero_dim \fi: \tex_par:D \hook_use:
n {para/after}\@kernel@after@para@after }{\msg_error:nnnn {hooks}{para-mode}{en
d}{horizontal}}}}\tex_par:D
\mode_if_horizontal:TF ->\if_mode_horizontal: \__prg_TF_true:w \fi: \use_ii:nn
\use_ii:nn #1#2->#2
#1<-\mode_if_inner:F {\tex_unskip:D \hook_use:n {para/end}\@kernel@after@para@e
nd \mode_if_horizontal:TF {\if_int_compare:w 11=\tex_lastnodetype:D \tex_hskip:
D \c_zero_dim \fi: \tex_par:D \hook_use:n {para/after}\@kernel@after@para@after
}{\msg_error:nnnn {hooks}{para-mode}{end}{horizontal}}}
#2<-\tex_par:D
\g__para_standard_everypar_tl ->\box_gset_to_last:N \g_para_indent_box \group_b
egin: \tex_par:D \group_end: \tex_everypar:D {\msg_error:nnnn {hooks}{para-mode
}{before}{vertical}}\@kernel@before@para@before \hook_use:n {para/before}\group
_begin: \tex_everypar:D {}\skip_zero:N \tex_parskip:D \tex_noindent:D \group_en
d: \tex_everypar:D {\g__para_standard_everypar_tl }\@kernel@before@para@begin \
hook_use:n {para/begin}\if_mode_horizontal: \else: \msg_error:nnnn {hooks}{para
-mode}{begin}{vertical}\fi: \__para_handle_indent: \the \toks 11
\box_gset_to_last:N #1->\tex_global:D \tex_setbox:D #1\tex_lastbox:D
#1<-\g_para_indent_box
\@kernel@before@para@before ->
\hook_use:n #1->\if_cs_exist:w __hook #1\cs_end: \cs:w __hook #1\exp_after:wN \
cs_end: \fi:
#1<-para/before
\__hook para/before ->\__hook_toplevel para/before \__hook_next para/before
\__hook_toplevel para/before ->
\__hook_next para/before ->
\skip_zero:N #1->#1=\c_zero_skip
#1<-\tex_parskip:D
\@kernel@before@para@begin ->
\hook_use:n #1->\if_cs_exist:w __hook #1\cs_end: \cs:w __hook #1\exp_after:wN \
cs_end: \fi:
#1<-para/begin
\__hook para/begin ->\__hook_toplevel para/begin \__hook_next para/begin
\__hook_toplevel para/begin ->
\__hook_next para/begin ->
\__para_handle_indent: ->\box_use_drop:N \g_para_indent_box
\par ->\scan_stop: \mode_if_horizontal:TF {\mode_if_inner:F {\tex_unskip:D \hoo
k_use:n {para/end}\@kernel@after@para@end \mode_if_horizontal:TF {\if_int_compa
re:w 11=\tex_lastnodetype:D \tex_hskip:D \c_zero_dim \fi: \tex_par:D \hook_use:
n {para/after}\@kernel@after@para@after }{\msg_error:nnnn {hooks}{para-mode}{en
d}{horizontal}}}}\tex_par:D
\mode_if_horizontal:TF ->\if_mode_horizontal: \__prg_TF_true:w \fi: \use_ii:nn
\__prg_TF_true:w \fi: \use_ii:nn ->\fi: \use_i:nn
\use_i:nn #1#2->#1
#1<-\mode_if_inner:F {\tex_unskip:D \hook_use:n {para/end}\@kernel@after@para@e
nd \mode_if_horizontal:TF {\if_int_compare:w 11=\tex_lastnodetype:D \tex_hskip:
D \c_zero_dim \fi: \tex_par:D \hook_use:n {para/after}\@kernel@after@para@after
}{\msg_error:nnnn {hooks}{para-mode}{end}{horizontal}}}
#2<-\tex_par:D
\mode_if_inner:F ->\if_mode_inner: \__prg_F_true:w \fi: \use:n
\use:n #1->#1
#1<-\tex_unskip:D \hook_use:n {para/end}\@kernel@after@para@end \mode_if_horizo
ntal:TF {\if_int_compare:w 11=\tex_lastnodetype:D \tex_hskip:D \c_zero_dim \fi:
\tex_par:D \hook_use:n {para/after}\@kernel@after@para@after }{\msg_error:nnnn
{hooks}{para-mode}{end}{horizontal}}
\hook_use:n #1->\if_cs_exist:w __hook #1\cs_end: \cs:w __hook #1\exp_after:wN \
cs_end: \fi:
#1<-para/end
\__hook para/end ->\__hook_toplevel para/end \__hook_next para/end
\__hook_toplevel para/end ->
\__hook_next para/end ->
\@kernel@after@para@end ->
\mode_if_horizontal:TF ->\if_mode_horizontal: \__prg_TF_true:w \fi: \use_ii:nn
\__prg_TF_true:w \fi: \use_ii:nn ->\fi: \use_i:nn
\use_i:nn #1#2->#1
#1<-\if_int_compare:w 11=\tex_lastnodetype:D \tex_hskip:D \c_zero_dim \fi: \tex
_par:D \hook_use:n {para/after}\@kernel@after@para@after
#2<-\msg_error:nnnn {hooks}{para-mode}{end}{horizontal}
\hook_use:n #1->\if_cs_exist:w __hook #1\cs_end: \cs:w __hook #1\exp_after:wN \
cs_end: \fi:
#1<-para/after
\__hook para/after ->\__hook_toplevel para/after \__hook_next para/after
\__hook_toplevel para/after ->
\__hook_next para/after ->
\@kernel@after@para@after -> which is the trace with current LaTeX of this innocent input:
and trust me you don't want to see what happens if Notice also that a great many of the advantages of this programming layer is that it encapsulates extensions to the TeX/LaTeX of the 20th century with the e-TeX extensions of 1999 and more recent engine-level extensions. This is all hidden to casual student of this programming layer who will not know that this is what makes the thing tick. Things such as For time being I think it is better that we do not use in Sphinx LaTeX code the L3 programming layer and stick to old coding style. |
was superseded by #10648 |
Rounded corners for the framing of code-blocks, via a new configuration verbatimradius of 'sphinxsetup', which defaults
to 0pt.
If this dimension is non zero, the LaTeX package pict2e will be loaded
to construct frames with rounded corners for code-blocks. Also, the
default background color will then change from white to a light
gray. And if the LaTeX package pict2e was not found, a LaTeX warning is
issued during PDF build.
Feature or Bugfix
By default, nothing changes: one needs to use the
verbatimradius
LaTeX key inside'sphinxsetup'
. And if one sets it to a strictly postitive value, the layout in PDFs should not be modified ifverbartimsep
andverbatimborder
stay the same.Detail
another example (the above was with default colors triggered from setting
verbatimradius>0pt
)This uses the pict2e which is light weight. But on Ubuntu it is part of the somewhat big texlive-pictures, which contains all of pgf+TikZ...
I also tested with a tcolorbox based implementation but there is not much interest if the box is not made much fancier. The impact on build time is very noticeable on big documents if using
\tcbox
in place of our custom own-defined rounded box based on the pict2e interface to the PDF operators.Compatible with all engines as far as I know. But not tested for platex (Japanese).