ASCII colors not quite properly printed in LaTeX
From the LaTeX showcase PDF:

This seems tricky to do, because it looks like the formatting commands don't get written to the IO buffer:
(image to see the formatting)
julia> printstyled("Hello"; bold = true)
Hello
julia> printstyled(stdout, "Hello"; bold = true)
Hello
julia> io = IOBuffer()
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)
julia> printstyled(io, "Hello"; bold = true)
julia> String(take!(io))
"Hello"
You need to do:
julia> io = IOBuffer()
julia> ioc = IOContext(io, :color=>true)
julia> printstyled(ioc, "Hello"; bold = true)
julia> String(take!(io))
"\e[0m\e[1mHello\e[22m"
So then the follow-up question is: can the {minted} environment in LaTeX handle those control characters appropriately? I'd assume not, because the styling happens separately.
\begin{minted}{julia}
julia> io = IOBuffer()
julia> ioc = IOContext(io, :color=>true)
julia> printstyled(ioc, "Hello"; bold = true)
julia> String(take!(io))
"\e[0m\e[1mHello\e[22m"
\end{minted}
yields
So then the follow-up question is: can the {minted} environment in LaTeX handle those control characters appropriately? I'd assume not, because the styling happens separately.
Would need to do the same as the HTML code does (parse it and render). See https://github.com/JuliaDocs/Documenter.jl/pull/1441, https://github.com/JuliaDocs/ANSIColoredPrinters.jl
I am not sure you can directly set colors for certain parts of a minted block. Perhaps to fix this perfectly one would need to render directly to latex code for code blocks without relying on any package.
It would not be too difficult to add LaTexPrinter to ANSIColoredPrinters.
(I never knew KaTeX supported the
xcolor syntax before!)
One of the issues is terminal-dependent colors.
For Documenter.LaTeX() (i.e. LaTeXWriter), ANSIColoredPrinters.LaTeXPrinter will have to mimic the internal behavior of minted.
Although this is not a Documenter.jl issue, I think we need to accept some restrictions on LaTeX objects embedded within HTML.
\begin{minted}[escapeinside=@@]{jlcon}
julia> src = IOBuffer("Is \e[48;5;250mthis \e[38;5;198mword \e[mcolored?");
@@
julia> LaTeXPrinter(src)
@Is \colorbox[HTML]{bcbcbc}{this {\color[HTML]{ff0087}word }}colored?@
\end{minted}
escapeinside may be a possible technique. However, it is considered somewhat fragile.
cf. https://github.com/gpoore/minted/blob/main/source/minted.pdf