bug-texinfo
[Top][All Lists]

## Re: generic color support for texinfo.tex

 From: Jean Abou Samra Subject: Re: generic color support for texinfo.tex Date: Wed, 24 Nov 2021 23:00:45 +0100 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1



Le 24/11/2021 à 21:50, Gavin Smith a écrit :

On Wed, Nov 24, 2021 at 3:17 PM Werner LEMBERG <wl@gnu.org> wrote:

For the LilyPond documentation we are going to use pygments to do
automatic colour highlighting of LilyPond snippets.  We also want to
support this feature in the PDF manuals.  To do so I ask you to apply
something like the following patch to make @setcolor work in
@example environments, too.

I'm not sure why it's needed; could you send an example of the kind of
input you are trying to make work?

I am guessing that it is @setcolor with an argument inside of @example, like

@example
test
@setcolor{0.7 0.7 0.2}brown
@end example

This doesn't work, as you found out. To work around this, you can
define a macro:

@tex
\global\def\colorBrown{0.7 0.7 0.2}
@end tex

@example
test
@setcolor{@colorBrown}brown
@end example

This works because the catcode of the space is "fixed" at the time of
the macro definition.

(Obviously this should be conditional on TeX and probably PDF output
in your document, using @iftex and so on.)

Catcodes are a confusing part of texinfo.tex and I'd rather not have
to do anything to make them more complicated. I'm not convinced that
your change would always work; for example, if the @setcolor command
is nested inside the argument to another command, then it's possible
that spaces inside its argument have their catcodes fixed at the time
of that argument being read, depending on how the other command was
defined.

Do you think that the workaround I suggested would be good enough for



There's a bit more work involved in our highly complex
build system to output an includable file comprising
these color definitions. I can probably get it to work
though.

The one case where it would become somewhat more
inconvenient is if someone (I'm not focusing on it
right now) tries to upstream the small Texinfo
Pygments formatter that we're using. The Formatter
API has a get_style_defs() method of Formatter object,
which is supposed to output the style definitions
required once to define highlighting colors. In HTML,
this is a CSS stylesheet; in LaTeX, it defines commands
for styling each token type. This API is accessible
through a switch of the command-line interface. It
would be a bit tricky to define what it returns for
Texinfo since there would be one CSS stylesheet and one
bit of content in Texinfo syntax for TeX. However,
it can probably be dealt with by slightly hijacking
the string parameter of get_style_defs(), which
is supposed to define a kind of prefix (inserted
as a level of specificity before class names in
CSS and taken as a command prefix in LaTeX) to
support things like "css" or
"css;css_prefix='.highlight-class'".


It would be nice to have @setcolor as an 'official' command that
also works with other output formats (for info, this would probably be
a no-op), but we can live without that since we let pygments
directly manipulate the HTML output.

Good to hear that you are managing to do syntax highlighting in HTML.



Pygments does all the work for us. It's a nifty
library.

Best regards,
Jean



reply via email to