What I intend to do...
Initially, I wanted to write a series of environments that help me typeset verbatim environments. For example, I would like
\begin{myverb}{stylea}
\end{myverb}
to be equivalent to:
\begin{minted}{fontsize=\small, bgcolor=white}
\end{minted}
Essentially, each key corresponds to a specific combination of parameters for minted
(or any other verbatim) environment. However, due to special implementations of verbatim environments in LaTeX, I realize that there is no easy way of doing this. By far, I only know two possible approaches:
- Use
tcblisting
+minted
with a self-defined style and use\tcbset
to change it programmatically. - Save the entire verbatim environment as file and read with
\input
.
(I skimmed through tcblisting
's source code, maybe these two approaches are fundamentally the same?)
Even though I think I have found a way of achieving my goals, I still want to ask the following questions because I am unable to explain many phenomena that happened throughout my own experiments. Please pardon my weak understandings on TeX and LuaTeX mechanisms.
My specific questions
From my understanding, by saving the verbatim environment into files, we are able to decouple our code from regular TeX parsing routine. In this case, the alternative outlet is the file system. In LuaTeX, another scripting engine (i.e. Lua) is introduced apart from TeX engine. I would like to know if it is possible to use LuaTeX to do this directly, without the need of file system I/O? Using
tex.print
does not work work as expected (see question 2). Essentially, is it possible for LuaTeX to\input
from Lua strings, instead of files?Why does the first one work but the second doesn't?
% https://tex.stackexchange.com/questions/410481/verbatim-with-direct-lua/410482#410482
\directlua{tex.print([[\unexpanded{\begin{verbatim}]]..'one\rtwo'..[[\end{verbatim}}]])}
% using minted package
\directlua{tex.print([[\unexpanded{\begin{minted}{python}]]..'one\rtwo'..[[\end{minted}}]])}
- Why does
tcblisting
work withminted
back-end?
% using minted via tcblisting
\directlua{tex.print([[\unexpanded{\begin{tcblisting}{listing engine=minted, minted language=python}]]..'one\rtwo'..[[\end{tcblisting}}]])}
- Why does
\directlua
work butluacode*
doesn't?
\directlua{
tex.print([[\unexpanded{\begin{verbatim}abc\end{verbatim}}]])
}
\begin{luacode*}
tex.print([[\unexpanded{\begin{verbatim}abc\end{verbatim}}]])
\end{luacode*}
Possible preamble
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{verbatim}
\usepackage{luacode}
\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted}