Open artemohanjanyan opened 6 years ago
this can easily be fixed with something like this in the latex preamble:
\definecolor{ansi30}{HTML}{262626}
\definecolor{ansi31}{HTML}{D70000}
\definecolor{ansi32}{HTML}{5F8700}
\definecolor{ansi33}{HTML}{AF8700}
\definecolor{ansi34}{HTML}{0087FF}
\definecolor{ansi35}{HTML}{AF005F}
\definecolor{ansi36}{HTML}{00AFAF}
\definecolor{ansi37}{HTML}{E4E4E4}
\definecolor{ansi38}{HTML}{1C1C1C}
\definecolor{ansi39}{HTML}{D75F00}
\definecolor{ansi310}{HTML}{585858}
\definecolor{ansi311}{HTML}{626262}
\definecolor{ansi312}{HTML}{808080}
\definecolor{ansi313}{HTML}{5F5FAF}
\definecolor{ansi314}{HTML}{8A8A8A}
\definecolor{ansi315}{HTML}{FFFFD7}
generated with:
from ansi2html.style import SCHEME
sol = SCHEME['solarized']
for i, n in enumerate(sol):
print("\\definecolor{ansi3%s}{HTML}{%s}" % (i, n.strip('#').upper()))
problematic is rather that ansi1
(and similar ones) is used as a \textcolor
while it should be converted to a \textbf{...}
instead. So, I ended up with things like: \textcolor{ansi1 ansi32}
which I fixed with the following sed in the meantime:
sed -i -e 's|textcolor{ansi1 \(ansi[0-9]*\)}\({[^}]*}\)|textbf{\\textcolor{\1}\2}|g' test.tex
More than two years passed, and the problem is still here.
Generating the \definecolor{...}
with the above Python script works - however the resulting file is still not LaTeX'able:
$ pdflatex t
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./t.tex
LaTeX2e <2018-12-01>
(/usr/local/texlive/2019/texmf-dist/tex/latex/koma-script/scrartcl.cls
Document Class: scrartcl 2019/02/01 v3.26b KOMA-Script document class (article)
(/usr/local/texlive/2019/texmf-dist/tex/latex/koma-script/scrkbase.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/koma-script/scrbase.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/koma-script/scrlfile.sty)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)
(/usr/local/texlive/2019/texmf-dist/tex/latex/koma-script/typearea.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/inputenc.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: `fancyvrb' v3.2a <2019/01/15> (tvz))
(/usr/local/texlive/2019/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-def/pdftex.def)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/dvipsnam.def))
No file t.aux.
(/usr/local/texlive/2019/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)
! Package xcolor Error: Undefined color `ansi38-238'.
See the xcolor package documentation for explanation.
Type H <return> for immediate help.
...
l.32 ...??─────────────}
?
Here's the file in question:
// Closures, lambda functions
#![allow(dead_code)]
use std::iter::Iterator;
pub type Weird2 = dyn Iterator<Item = i32>;
pub fn gen_iter() -> impl Iterator<Item = i32> {
(0..)
}
pub fn double_it(a: impl Iterator<Item = i32>) -> impl Iterator<Item = i32> {
a.map(|v| v + v)
}
pub fn sum_up(a: impl Iterator<Item = i32>) -> i32 {
let s = 0;
a.fold(s, |v, s| v + s)
}
pub fn take_more() {}
Here's the generating command:
$ bat --paging=never --color=always --style=full file1.rs | ansi2html -f 12 -L --scheme=osx > t.tex
Here's the preamble manually added to t.tex
:
\definecolor{ansi30}{HTML}{000000}
\definecolor{ansi31}{HTML}{C23621}
\definecolor{ansi32}{HTML}{25BC24}
\definecolor{ansi33}{HTML}{ADAD27}
\definecolor{ansi34}{HTML}{492EE1}
\definecolor{ansi35}{HTML}{D338D3}
\definecolor{ansi36}{HTML}{33BBC8}
\definecolor{ansi37}{HTML}{CBCCCD}
\definecolor{ansi38}{HTML}{000000}
\definecolor{ansi39}{HTML}{C23621}
\definecolor{ansi310}{HTML}{25BC24}
\definecolor{ansi311}{HTML}{ADAD27}
\definecolor{ansi312}{HTML}{492EE1}
\definecolor{ansi313}{HTML}{D338D3}
\definecolor{ansi314}{HTML}{33BBC8}
\definecolor{ansi315}{HTML}{CBCCCD}
Here's the t.tex
file as attempted above:
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{fancyvrb}
\usepackage[usenames,dvipsnames]{xcolor}
% \definecolor{red-sd}{HTML}{7ed2d2}
\definecolor{ansi30}{HTML}{000000}
\definecolor{ansi31}{HTML}{C23621}
\definecolor{ansi32}{HTML}{25BC24}
\definecolor{ansi33}{HTML}{ADAD27}
\definecolor{ansi34}{HTML}{492EE1}
\definecolor{ansi35}{HTML}{D338D3}
\definecolor{ansi36}{HTML}{33BBC8}
\definecolor{ansi37}{HTML}{CBCCCD}
\definecolor{ansi38}{HTML}{000000}
\definecolor{ansi39}{HTML}{C23621}
\definecolor{ansi310}{HTML}{25BC24}
\definecolor{ansi311}{HTML}{ADAD27}
\definecolor{ansi312}{HTML}{492EE1}
\definecolor{ansi313}{HTML}{D338D3}
\definecolor{ansi314}{HTML}{33BBC8}
\definecolor{ansi315}{HTML}{CBCCCD}
\title{}
\fvset{commandchars=\\\{\}}
\begin{document}
\begin{Verbatim}
\textcolor{ansi38-238}{───────┬────────────────────────────────────────────────────────────────────────}
\textcolor{ansi38-238}{│ }File: \textcolor{ansi1}{file1.rs}
\textcolor{ansi38-238}{───────┼────────────────────────────────────────────────────────────────────────}
\textcolor{ansi38-238}{ 1} \textcolor{ansi38-238}{│} \textcolor{ansi38-242}{//}\textcolor{ansi38-242}{ Closures, lambda functions}
\textcolor{ansi38-238}{ 2} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{#!}\textcolor{ansi38-231}{[}\textcolor{ansi38-231}{allow}\textcolor{ansi38-231}{(}\textcolor{ansi38-231}{dead_code}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{]}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 3} \textcolor{ansi38-238}{│} \textcolor{ansi38-203}{use}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{std}\textcolor{ansi38-231}{::}\textcolor{ansi38-231}{iter}\textcolor{ansi38-231}{::}\textcolor{ansi38-231}{Iterator}\textcolor{ansi38-231}{;}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 4} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 5} \textcolor{ansi38-238}{│} \textcolor{ansi38-203}{pub}\textcolor{ansi38-231}{ }\textcolor{ansi38-81}{type}\textcolor{ansi38-231}{ }\textcolor{ansi38-149}{Weird2}\textcolor{ansi38-231}{ }\textcolor{ansi38-203}{=}\textcolor{ansi38-231}{ dyn }\textcolor{ansi38-231}{Iterator}\textcolor{ansi38-231}{<}\textcolor{ansi38-231}{Item = }\textcolor{ansi38-81}{i32}\textcolor{ansi38-231}{>}\textcolor{ansi38-231}{;}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 6} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 7} \textcolor{ansi38-238}{│} \textcolor{ansi38-203}{pub}\textcolor{ansi38-231}{ }\textcolor{ansi38-81}{fn}\textcolor{ansi38-231}{ }\textcolor{ansi38-149}{gen_iter}\textcolor{ansi38-231}{(}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{->}\textcolor{ansi38-231}{ impl }\textcolor{ansi38-231}{Iterator}\textcolor{ansi38-231}{<}\textcolor{ansi38-231}{Item = }\textcolor{ansi38-81}{i32}\textcolor{ansi38-231}{>}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{{}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 8} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{ }\textcolor{ansi38-231}{(}\textcolor{ansi38-141}{0}\textcolor{ansi38-203}{..}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 9} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 10} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 11} \textcolor{ansi38-238}{│} \textcolor{ansi38-203}{pub}\textcolor{ansi38-231}{ }\textcolor{ansi38-81}{fn}\textcolor{ansi38-231}{ }\textcolor{ansi38-149}{double_it}\textcolor{ansi38-231}{(}\textcolor{ansi38-208}{a}\textcolor{ansi38-231}{:}\textcolor{ansi38-231}{ impl }\textcolor{ansi38-231}{Iterator}\textcolor{ansi38-231}{<}\textcolor{ansi38-231}{Item = }\textcolor{ansi38-81}{i32}\textcolor{ansi38-231}{>}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{->}\textcolor{ansi38-231}{ impl }\textcolor{ansi38-231}{Iterator}\textcolor{ansi38-231}{<}\textcolor{ansi38-231}{Item = }\textcolor{ansi38-81}{i32}\textcolor{ansi38-231}{>}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{{}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 12} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{ a}\textcolor{ansi38-231}{.}\textcolor{ansi38-81}{map}\textcolor{ansi38-231}{(}\textcolor{ansi38-231}{|}\textcolor{ansi38-208}{v}\textcolor{ansi38-231}{|}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{v }\textcolor{ansi38-203}{+}\textcolor{ansi38-231}{ v}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 13} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 14} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 15} \textcolor{ansi38-238}{│} \textcolor{ansi38-203}{pub}\textcolor{ansi38-231}{ }\textcolor{ansi38-81}{fn}\textcolor{ansi38-231}{ }\textcolor{ansi38-149}{sum_up}\textcolor{ansi38-231}{(}\textcolor{ansi38-208}{a}\textcolor{ansi38-231}{:}\textcolor{ansi38-231}{ impl }\textcolor{ansi38-231}{Iterator}\textcolor{ansi38-231}{<}\textcolor{ansi38-231}{Item = }\textcolor{ansi38-81}{i32}\textcolor{ansi38-231}{>}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{->}\textcolor{ansi38-231}{ }\textcolor{ansi38-81}{i32}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{{}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 16} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{ }\textcolor{ansi38-81}{let}\textcolor{ansi38-231}{ s }\textcolor{ansi38-203}{=}\textcolor{ansi38-231}{ }\textcolor{ansi38-141}{0}\textcolor{ansi38-231}{;}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 17} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{ a}\textcolor{ansi38-231}{.}\textcolor{ansi38-81}{fold}\textcolor{ansi38-231}{(}\textcolor{ansi38-231}{s}\textcolor{ansi38-231}{,}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{|}\textcolor{ansi38-208}{v}\textcolor{ansi38-231}{,}\textcolor{ansi38-231}{ }\textcolor{ansi38-208}{s}\textcolor{ansi38-231}{|}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{v }\textcolor{ansi38-203}{+}\textcolor{ansi38-231}{ s}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 18} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 19} \textcolor{ansi38-238}{│} \textcolor{ansi38-231}{}
\textcolor{ansi38-238}{ 20} \textcolor{ansi38-238}{│} \textcolor{ansi38-203}{pub}\textcolor{ansi38-231}{ }\textcolor{ansi38-81}{fn}\textcolor{ansi38-231}{ }\textcolor{ansi38-149}{take_more}\textcolor{ansi38-231}{(}\textcolor{ansi38-231}{)}\textcolor{ansi38-231}{ }\textcolor{ansi38-231}{{}\textcolor{ansi38-231}{}}\textcolor{ansi38-231}{}
\textcolor{ansi38-238}{───────┴────────────────────────────────────────────────────────────────────────}
\end{Verbatim}
\end{document}
@ralphbean ping? Would you be able to address this issue?
When converting to LaTeX in non-inline mode,
ansi2html
produces commands like\textcolor{ansi33}
, althoughansi*
colors are not defined.Maybe just use
\textcolor[HTML]{aa5500}
like in inline mode?