Open make-github-pseudonymous-again opened 2 days ago
Could you make your example complete thus compilable? For example Load necessary packages, define needed counter, provide loaded external file.js
, etc.
BTW you set to use listings
engine, but the text
lexer is only passed on to minted
-specific option, thus is ignored. And the default setting listing options={style=tcblatex}
would take effect.
listing engine=listings,
minted language=#1,
listing file={#2},
minted options={%
autogobble,%
linenos,%
breaklines,%
breakanywhere%
},
BTW you set to use
listings
engine, but thetext
lexer is only passed on tominted
-specific option, thus is ignored. And the default settinglisting options={style=tcblatex}
would take effect.
My mistake. Tried multiple approaches.
Could you make your example complete thus compilable? For example Load necessary packages, define needed counter, provide loaded external file.js, etc.
Will do.
@muzimuzhi Here you go
# Makefile
TARGET := listings
LTX := xelatex -shell-escape -interaction=nonstopmode -halt-on-error
$(TARGET).pdf: $(TARGET).tex package/dist/preact.js
$(LTX) $(TARGET).tex
package/dist/preact.js:
wget https://registry.npmjs.org/preact/-/preact-10.25.0.tgz
tar -xzf preact-10.25.0.tgz
% listings.tex
\documentclass{article}
\newcounter{filePrg}
\usepackage{geometry}
\geometry{paper=letterpaper,margin=2cm}
\usepackage[dvipsnames]{xcolor}
\usepackage[many]{tcolorbox}
\tcbuselibrary{minted}
\newtcbinputlisting[use counter=filePrg, number format=\arabic]{\codeFromFile}[3]{%
listing engine=minted,
minted language=#1,
listing file={#2},
minted options={%
autogobble,%
linenos,%
breaklines,%
breakanywhere%
},
listing only,
size=title,
arc=1.5mm,
breakable,
enhanced jigsaw,
colframe=brown,
coltitle=White,
boxrule=0.5mm,
colback=white,
coltext=Black,
title=\textbf{File \thetcbcounter}\textbf{:} \textit{#3}%
}
\usepackage{cleveref}
\crefname{filePrg}{file program}{file programs}
\begin{document}
\codeFromFile{text}{package/dist/preact.js}{package/dist/preact.js}
\end{document}
Good news: With listing engine=minted
, your example compiles without errors.
Bad news: The output is still wrong. The line breaking mechanism provided by minted
just didn't work.
![image](https://github.com/user-attachments/assets/46bcd6b2-768a-41da-be2c-51ba0f47a4ca)
This is reproducible with fvextra
only (which is the source of breaklines
and breakanywhere
minted
options), using
\documentclass{article}
\usepackage{fvextra}
\begin{document}
\VerbatimInput[linenos, breaklines, breakanywhere]{package/dist/preact.js}
\end{document}
PS: The initial error was thrown by listings
internals (notice the lst
prefix). But with appropriate number of characters, fvextra
(thus minted
) would throw the same error, which comes down to one of TeX's limitations.
! Dimension too large. \lsthk@InitVarsEOL ->\ifdim \lst@currlwidth >\lst@maxwidth \global \lst@maxw... l.1 ...rminated:function(){}});return new l(j,p)};
I filed https://github.com/gpoore/fvextra/issues/28 and added some discussion there.
Even though the line breaking mechanism may be fixed for super long line (https://github.com/gpoore/fvextra/issues/28#issuecomment-2510129720), you still hit the limitation of fvextra
that a broken line cannot across multiple pages, thus cannot be broken into sequences of tcolorbox
es.
In short, currently there seems to be no direct support for typesetting super long line of code (arbitrary combination of caracters), with code highlighting and automatic line and page breaking. Maybe url
package is helpful.
I am trying to generate a PDF with the listings of a bundled JavaScript package. I am getting the following error with minified JavaScript code, probably because the file is a single line of code (>15k characters):
This error occurs even when using the
text
lexer:Is there any way to make this work?