leo-colisson / robust-externalize

A LaTeX library to cache pictures (including tikz, python code, and more) in a robust, customizable, and pure way.
7 stars 2 forks source link

Nondescriptive error message #33

Open user202729 opened 4 months ago

user202729 commented 4 months ago

Source code:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{listings}
\usepackage{robust-externalize}
\begin{document}
\begin{CacheMeCode}{python print code and result}
print("Hello world")
\end{CacheMeCode}
\end{document}

Error message:

! Package Listings Error: Couldn't load requested style.
tobiasBora commented 4 months ago

Thanks. Here the issue is that you forgot to load \usepackage{pythonhighlight} as documented… but I'm not so sure if I can do anything to provide a better error message as this error is fired by listings… so I would say that this bug report should be reported to listings so that they print, at least , the name of the missing style. I could maybe try to check if this style exists while executing python print code and result, and give an error if pythonhighlight is not loaded… but people might have customized it to load a different style. The only option I can think of to provide a better error message is to check after loading the style of the user if they changed the default __ROBEXT_PYTHON_LSTINPUT_STYLE__ placeholder. If not, we check if pythonhighlight is loaded, and if not, we provide an error… might be doable, I'll think about it.

user202729 commented 4 months ago

That sounds reasonable. https://tex.stackexchange.com/q/16199/250119 can be used to check if the package is loaded.

Speaking of which

\robExtSetPlaceholder{__ROBEXT_PYTHON_LSTINPUT_STYLE__}{frame=single, breakindent=.5\textwidth, frame=single, breaklines=true, style=mypython}

Seems frame=single is doubled for no reason?


Actually, listings package already print out the erroneous style name (mypython) in a subsequent error message.

user202729 commented 3 months ago

For now, pythonhighlight package updated the internal listings style name to pythonhighlight-style, which hopefully would make the error message more understandable. (Because you this you would also need to update the mypython reference in your package correspondingly)

Next step might be to ask listings package to print the name on the first error message.

user202729 commented 3 months ago

It's a bit messier than I thought. There's the alternative of using \AddToHook{package/pythonhighlight/after}{something} as well.

tobiasBora commented 3 months ago

Yeah, it is not so easy to do it properly without breaking backward compatibility of my package. What you describe might work, but uses \AddToHook that I try to avoid as it is only available since 2020 (quite recent in LaTeX life), that might still be in use by some editors. Also, it assumes, I guess, that I can define an alias for an lststyle. That might be possible, but I don't know.