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

Clearer error message? #9

Closed dflvunoooooo closed 6 months ago

dflvunoooooo commented 7 months ago

First of all, thank you for this great package! I found a small issue.

If I escape a math environment inside a tikzpicture with \text{…} instead of \mathrm{…} robust-externalize throws a cryptic error: Package robExt Error: The pdf file. Without the CachMe environment the tikzpicture is working fine.

Here is my minimalistic example:

\documentclass{scrreport}

\usepackage{amsmath}                                % Unverzichtbare Mathe-Befehle.
\usepackage{tikz}                                   % Für Zeichnungen direkt in LaTeX

\usepackage{robust-externalize}
\robExtConfigure{
    enable fallback to manual mode,
}

\begin{document}

\(T_\text{Test}\)

\begin{figure}
    \begin{CacheMe}{tikzpicture}[scale=2]
        \draw (0,1.5) node[left] {\small \(E_\mathrm{F}\)} -- (3,1.5);
        \draw (0,2.1) node[left] {\small \textcolor{red!80}{$E_\text{D}$}} -- (3,2.1);
    \end{CacheMe}
    \centering
    \caption{Ein Beispiel}
\end{figure}

\end{document}
tobiasBora commented 7 months ago

Thanks for the bug report. So your issue is that you simply need to also load amsmath in the cached picture environment: under the hood, this library "copy/paste" the text into a new latex file and compile it separately, so you need to be sure amsmath is loaded also there with:

\robExtConfigure{
  add to preset={tikz}{
    add to preamble={\usepackage{amsmath}},
  },
}

So regarding the cryptic error, how are you compiling? In my case, if I compile in command line for instance I get:

image

So you clearly see that they complain because \text is not defined (text above the main error message), and the actual error message prints a link to the file robustExternalize/robExt-B34F405306396F2311B2D2EE2E773D72.log. that also contains this error… I don't know why you only get the first line, so I don't know how to make a much clearer message.

I also tried on emacs and I get directly the ERROR: Undefined control sequence. (so it stops even before reading my message), the only issue is that it moves me back to a new empty file instead of the line where the message actually occurs, but I have no idea if I can even let latex/emacs know that the error should be reported on the main file instead of the cached file… So when the error gets too complicated to debug I just spawn a shell and manually compile the document there, but I'd love to find a more resilient way to print a nicer error message, just that I don't know how to do/if latex even allows me more flexibility on this.

Full code:

\documentclass{scrreport}

\usepackage{amsmath}                                % Unverzichtbare Mathe-Befehle.
\usepackage{tikz}                                   % Für Zeichnungen direkt in LaTeX

\usepackage{robust-externalize}
\robExtConfigure{
  enable fallback to manual mode,
  add to preset={tikz}{
    add to preamble={\usepackage{amsmath}},
  },
}

\begin{document}

\(T_\text{Test}\)

\begin{figure}
    \begin{CacheMe}{tikzpicture}[scale=2]
        \draw (0,1.5) node[left] {\small \(E_\mathrm{F}\)} -- (3,1.5);
        \draw (0,2.1) node[left] {\small \textcolor{red!80}{$E_{\text{D}}$}} -- (3,2.1);
    \end{CacheMe}
    \centering
    \caption{Ein Beispiel}
\end{figure}

\end{document}
% Local Variables:
% TeX-command-extra-options: "-shell-escape -halt-on-error"
% End:
tobiasBora commented 7 months ago

How are you compiling this document? I can maybe see it it is possible to print a better error message for this platform… or maybe you just need to click a small arrow to print the full error message?

dflvunoooooo commented 7 months ago

Thank you for your fast response! I did not think to check further errors, because it was working without CacheMe and I loaded amsmath in the preamble. But I can confirm that your solution is working!

I am working in TexStudio and use XeLatex with xelatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex.

I found an error in the log in the folder robustExternalize. It says the same:

! Undefined control sequence.
<argument> $E_\text 
                    {D}$
l.15 ...{\small \textcolor {red!80}{$E_\text {D}$}
                                                  } -- (3,2.1);\end {tikzpic...

Here is how much of TeX's memory you used:
 12339 strings out of 477985
 256165 string characters out of 5840058
 1849388 words of memory out of 5000000
 32347 multiletter control sequences out of 15000+600000
 514110 words of font info for 38 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 102i,8n,104p,420b,595s stack positions out of 10000i,1000n,20000p,200000b,200000s
!  ==> Fatal error occurred, no output PDF file produced!

But in log of the main folder is on mention of the undefined control sequence. There is only:

Source saved in robustExternalize/robExt-B34F405306396F2311B2D2EE2E773D72.tex.
[robExt]We will start the compilationusing: cd robustExternalize/ && pdflatex -
halt-on-error "robExt-B34F405306396F2311B2D2EE2E773D72.tex".
runsystem(cd robustExternalize/ && pdflatex -halt-on-error "robExt-B34F40530639
6F2311B2D2EE2E773D72.tex")...executed.

! Package robExt Error: The pdf file
(robExt)               
robustExternalize/robExt-B34F405306396F2311B2D2EE2E773D72.pdf
(robExt)                is not present. The compilation command "cd
(robExt)                robustExternalize/ && pdflatex -halt-on-error
(robExt)                "robExt-B34F405306396F2311B2D2EE2E773D72.tex"" used
(robExt)                to compile the environment on line 24 certainly
(robExt)                failed, see logs above or in
(robExt)               
robustExternalize/robExt-B34F405306396F2311B2D2EE2E773D72.log.

Type <return> to continue.
 ...                                              

l.24 ^^I\end
            {CacheMe}

LaTeX does not know anything more about this error, sorry.
tobiasBora commented 7 months ago

So in command line, XeLaTeX does print the same error message as above when run in the command line, but I realized it is not written directly in the log file, so TexStudio does not print it. A quick woraround is just to compile in the command line or open the above .log file, but it is not really satisfactory. I will try to investigate how to solve this (maybe using a shell redirection to a file and printing this file directly in the log would do the job… but I am a bit worried by fact that redirections might be OS/shell dependent…). I asked this question for now.

dflvunoooooo commented 7 months ago

Thank you. And as mentioned, you can find the log in the log of the corresponding figure in the robustExternalize folder. But of cause it would be better to to see the correct error in TexStudio.

tobiasBora commented 7 months ago

Ok, the error message is much clearer now (I tried to print the error line on the first line of the message, and the actual error is printed a few lines later), and looks like this in emacs, and it jumps directly at the good cacheme code block :

ERROR: Package robExt Error: On line 13: the pdf file

--- TeX said ---
(robExt)               
robustExternalize/robExt-F138F92CF36B5EB1030B416520ABB199.pdf
(robExt)                is not present. The compilation command "cd
(robExt)                robustExternalize/ && pdflatex -halt-on-error
(robExt)                "robExt-F138F92CF36B5EB1030B416520ABB199.tex"" used
(robExt)                to compile the environment on line 13 certainly
(robExt)                failed with errors:
(robExt)                vvvvvv
(robExt)                ! Package tikz Error: Giving up on this path. Did
(robExt)                you forget a semicolon?.
(robExt)                !  ==> Fatal error occurred, no output PDF file
(robExt)                produced!
(robExt)                
(robExt)                ^^^^^^
(robExt)                See full logs below or in
(robExt)               
robustExternalize/robExt-F138F92CF36B5EB1030B416520ABB199-compilation.log.

A similar message is also printed in TeXstudio, even if it does not print the full error message (I consider this as a bug of TeXstudio since emacs can handle it correctly). Nevetheless, the error message is quite clear when the word "error" appears in some lines, which is always the case when compiling latex stuff:

image

If it is not the case, then you can now look at the .log file:

image

This still need a bit of testing for windows, but for what I tried it should work out of the box.

dflvunoooooo commented 6 months ago

Yes. This error message is great now! :) Thank you again!

dflvunoooooo commented 6 months ago

I found another unclear error. But it appears with gnuplot. Shall I open a new issue? It has to do with the problem, that gnuplottex does not work when there are spaces in the filename. But then the only error is Package robExt Error: On line 22: the pdf file and no log is created.

tobiasBora commented 6 months ago

No, you can add it here. I realize that I should print a few lines before and after the error also to make it clearer.

No log is created, really? Weird. Can you paste a MWE?

dflvunoooooo commented 6 months ago

Hm interesting. This code does provide a proper error message:

\documentclass{scrreport}

\usepackage{robust-externalize}
\setPlaceholder*{__ROBEXT_LATEX_ENGINE__}{xelatex}
\runHereAndInPreambleOfCachedFiles{
    \usepackage{gnuplottex}
    \usepackage{gnuplot-lua-tikz}           
}

\begin{document}

\begin{figure}
    \centering  
    \begin{CacheMeCode}{gnuplot, tikz}
        plot cos(x) title "Test2"
    \end{CacheMeCode}}
\end{figure}

\end{document}

I called the file robust-externalize leerzeichen.tex. The space is important.

This code on the other hand, does not create a precise error message und also no log file:

\documentclass{scrreport}

\usepackage{robust-externalize}
\setPlaceholder*{__ROBEXT_LATEX_ENGINE__}{xelatex}
\runHereAndInPreambleOfCachedFiles{
    \usepackage{gnuplottex}
    \usepackage{gnuplot-lua-tikz}           
}
\robExtConfigure{
    compile in parallel,
}
\cacheTikz

\begin{document}

\begin{figure}
    \centering  
    \begin{CacheMeCode}{gnuplot, tikz terminal={providevars test_variable}}
        test_variable = 5
        plot cos(x) title "Test2"
    \end{CacheMeCode}
    \caption{Variable = \robExtGpgetvar{test_variable}}
\end{figure}

\end{document}
dflvunoooooo commented 6 months ago

The error messages sometimes gets not properly displayed in Texstudio. There I can only see Package robExt Error: On line 50: the pdf file if something is wrong with my gnuplot code. But compiled with the command line it says

xargs -t -I "{}" -P 16 sh -c "{}" < "4.5_Elektrische_Leitfähigkeit_von_Metallen
_und_Halbleitern_bei_tiefen_Temperaturen_Gruppe_N-robExt-compile-missing-figure
s.sh"sh -c '( cd robustExternalize/ && gnuplot -c robExt-1520D0F3BDB123D4AB61CFD7E2876BAD.tex && echo ok > robExt-1520D0F3BDB123D4AB61CFD7E2876BAD.pdf) > robustExternalize/robExt-1520D0F3BDB123D4AB61CFD7E2876BAD-compilation.log 2>&1'
system returned with code 31488

! Package robExt Error: On line 50: the pdf file
(robExt)               
robustExternalize/robExt-1520D0F3BDB123D4AB61CFD7E2876BAD.pdf
(robExt)                is not present. The compilation command "cd
(robExt)                robustExternalize/ && gnuplot -c
(robExt)                "robExt-1520D0F3BDB123D4AB61CFD7E2876BAD.tex" &&
(robExt)                echo "ok" >
(robExt)                "robExt-1520D0F3BDB123D4AB61CFD7E2876BAD.pdf"" used
(robExt)                to compile the environment on line 50 certainly
(robExt)                failed with errors:
(robExt)                vvvvvv
(robExt)                
(robExt)                ^^^^^^
(robExt)                See full logs below or in
(robExt)               
robustExternalize/robExt-1520D0F3BDB123D4AB61CFD7E2876BAD-compilation.log.

Type <return> to continue.
 ...                                              

l.102 \end{document}

-------- We print now the full log --------
decimal_sign in locale is ,
         Read 535 points
         Skipped 535 points outside range [x=50:300]
"robExt-1520D0F3BDB123D4AB61CFD7E2876BAD.tex" line 29: No data to fit

-------- End of the full log --------

I don't know if this can be handled in robust-extrenalize.

dflvunoooooo commented 6 months ago

Found another unprecise error. If one tries to plot data in gnuplot but forgets to add the data file to the directory of main latex document, the error in texstudio is just Package robExt Error: On line 16: the pdf file. The error in commandline is

[robExt]We will start the compilationusing: cd robustExternalize/ && gnuplot -c
 "robExt-ABC41082ADB6EF46AFE4D61D09630D7A.tex" && echo "ok" > "robExt-ABC41082A
DB6EF46AFE4D61D09630D7A.pdf".

! Package robExt Error: On line 16: the pdf file
(robExt)               
robustExternalize/robExt-ABC41082ADB6EF46AFE4D61D09630D7A.pdf
(robExt)                is not present. The compilation command "cd
(robExt)                robustExternalize/ && gnuplot -c
(robExt)                "robExt-ABC41082ADB6EF46AFE4D61D09630D7A.tex" &&
(robExt)                echo "ok" >
(robExt)                "robExt-ABC41082ADB6EF46AFE4D61D09630D7A.pdf"" used
(robExt)                to compile the environment on line 16 certainly
(robExt)                failed with errors:
(robExt)                vvvvvv
(robExt)                
(robExt)                ^^^^^^
(robExt)                See full logs below or in
(robExt)               
robustExternalize/robExt-ABC41082ADB6EF46AFE4D61D09630D7A-compilation.log.

Type <return> to continue.
 ...                                              

l.16     \end{CacheMeCode}

The code is:

\documentclass{scrreport}

\usepackage{robust-externalize}
\setPlaceholder*{__ROBEXT_LATEX_ENGINE__}{xelatex}
\runHereAndInPreambleOfCachedFiles{
    \usepackage{gnuplot-lua-tikz}           
}
\usepackage{amsmath}

\begin{document}

\begin{figure}
    \centering  
    \begin{CacheMeCode}{gnuplot, dependencies={Versuch_4_5_Gruppe_N_am_01_12_2023.dat}, tikz terminal={providevars test_variable}}
        plot 'Versuch_4_5_Gruppe_N_am_01_12_2023.dat' using 3:($6/$5)
    \end{CacheMeCode}
    \caption{Variable = }
\end{figure}

\end{document}

To reproduce there is no file needed :)

tobiasBora commented 6 months ago

So the latest version should have better (and more configurable) error messages.

But first:

This code on the other hand, does not create a precise error message und also no log file:

Uhm, so the problem is that if the file contains a space, latex adds "…" around it, breaking the whole system… LaTeX is really full of edge cases. This should be fixed now.

But compiled with the command line it says …

Found another unprecise error.

So there are multiple issues/solutions: On the small message:

  1. First, we only print by default in the first, short error message lines that contain "error" or "invalid". This works well for latex, not great for gnuplot that does not print "error". So I just introduced |print whole file in error message| to print the whole log in the error message: this is enabled by default on gnuplot now.
  2. this works great in emacs, in texstudio you need to be more cautious since texstudio only prints lines containing "error". The workaround is either to look at the full log in the tex file, or to do:
    \robExtConfigure{
    prefix error message with=error,
    }

    and it will automatically add "error" in front of all lines, making them (at least the first part) readable in texstudio.

For the full log:

  1. in command line the full log is printable by typing "Enter" on the first small error. The error message is now more explicit on this.
  2. in texstudio, you can see this log file by going directly to the log file.

I let you try the newer version, hopefully you like it better.

dflvunoooooo commented 6 months ago

Uhm, so the problem is that if the file contains a space, latex adds "…" around it, breaking the whole system… LaTeX is really full of edge cases. This should be fixed now.

Wow, you fixed the space problem? I reported this bug to gnuplottex here, but I seemed hard work. I can confirm, spaces in names do work now :)

So there are multiple issues/solutions: On the small message:

Yes, in the command line the gnuplot error is no shown, very niche. The robust-externalize log is perfekt now. It only shows the gnuplot error, if I am not mistaken. Great, thank you again!

In Texstudio the message didn't change. The whole error message is in the main log, same as in command line. But Texstudio only seems to print this line ! Package robExt Error: On line 19: the pdf file from the main log. The other error messages are not shown, but they don't start with a !, if that matters?

And the whole error message is written two time in the main log, is this intended or is this because of the way the CacheMeCode gnuplot works?

tobiasBora commented 6 months ago

Wow, you fixed the space problem?

Yeah, I based my solution on https://tex.stackexchange.com/questions/418670/avoid-quotation-marks-when-using-jobname-or-currfilename

The robust-externalize log is perfekt now.

Great!

But Texstudio only seems to print this line

Have you tried typing:

\robExtConfigure{
    prefix error message with=Error,
}

? This is maybe precisely for texstudio so that it adds "Error" in front of any line.

And the whole error message is written two time in the main log, is this intended or is this because of the way the CacheMeCode gnuplot works?

I do write the small error message twice + the log to be sure the users cannot miss it ^^' For emacs it is important that the small error arrives before the log, otherwise you get moved to a non-existing file. And for people that compiles everything in one go without stopping at errors, I wanted the small error to appear first when scrolling from the end… hence this repetition:

small error
full log
small error

Maybe a bad idea, not sure, but I guess it can't be harmful.

dflvunoooooo commented 6 months ago

Yeah, I based my solution on https://tex.stackexchange.com/questions/418670/avoid-quotation-marks-when-using-jobname-or-currfilename

And you reported this at gnuplottex, great.

Have you tried typing:

Yes, should have mentioned that, sorry. The main log does look exactly the same, with or without that option. Does thexstudio need a ! in front of the error as well?

I do write the small error message twice + the log to be sure the users cannot miss it ^^' For emacs it is important that the small error arrives before the log, otherwise you get moved to a non-existing file. And for people that compiles everything in one go without stopping at errors, I wanted the small error to appear first when scrolling from the end… hence this repetition:

I don't mind. Just wanted to make sure it is intentional.

tobiasBora commented 6 months ago

The main log does look exactly the same

Well, it should not, you should have Error written in front of all lines:

image

But you are right, even with that texstudio does not report an error… I will try to see, but I would say this must be reported on texstudio.

dflvunoooooo commented 6 months ago

Yes, my log looks like the. As you noticed, texstudio does not show it. Is it possible to just print the error from the robExt log? There at least is a waring.

dflvunoooooo commented 6 months ago

But on the other hand, one can display the whole log in texstudio, by switching from the "log" to "error and warnings" tab.

Screenshot_20231221_142426

Screenshot_20231221_142637

tobiasBora commented 6 months ago

Yes sure, it is always possible to show the whole log. So I finally came with a different solution: since prefix error message was useless (so I removed it), you should now just type:

\robExtConfigure{
  texstudio
}

and it will add ! in front of all the log lines of presets that enabled print whole file in error message, which is now enabled by default in bash, python and gnuplot. This way, the error message is now significantly better in TeXstudio (I hope):

image

% !TeX document-id = {b7eb9edf-7e0e-4d1a-a5ae-901a3a25bfed}
\documentclass{scrreport}

\usepackage{amsmath}                                % Unverzichtbare Mathe-Befehle.
\usepackage{tikz}                                   % Für Zeichnungen direkt in LaTeX

\usepackage{robust-externalize}
\robExtConfigure{
  enable fallback to manual mode,
  texstudio,
}

\usepackage{verbatim}
\begin{document}

\begin{CacheMeCode}{gnuplot}
    plot cos(x) title "Test2"
\end{CacheMeCode}

\end{document}
% For textstudio:
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
% For emacs:
% Local Variables:
% TeX-command-extra-options: "-shell-escape -halt-on-error"
% End:
dflvunoooooo commented 6 months ago

Your code example above should run without any problems. Was that intended?

Yes, this is better now. It does not display the whole error, because a linebreak, I suppose. The original error is ! "robExt-D321779A95880D45A6FF22663D94F869.tex" line 5: warning: Cannot find or open file "Versuch_4_5_Gruppe_N_am_01_12_2023.dat" and in Texstudio only ! "robExt-D321779A95880D45A6FF22663D94F869.tex" line 5: warning: Cannot find or" is shown. But I can live with this. :)

On the other hand, this leads to a error flooding, when I set the tkiz terminal in gnuplot and omit the word terminal. But you can not have everything. Thank you for your work!

tobiasBora commented 6 months ago

Your code example above should run without any problems. Was that intended?

Ahah yes, since I had no gnuplot installed on my shell, I was using this code to test if I was indeed getting an error "you don't have gnuplot installed", sorry ^^'

It does not display the whole error, because a linebreak,

Yes LaTeX and texstudio are really anoying. I'm trying to ask here if there is a better solution https://tex.stackexchange.com/questions/705502/message-add-symbol-in-front-of-new-lines-even-if-there-is-a-line-break but the best thing would be for texstudio to parse errors correctly (tried to ask here and I got a link to the github issue https://github.com/texstudio-org/texstudio/issues/1410 and one told me:

texstudio is notorious for scrambling tex error messages, it will not even show a basic primitive tex undefined command error without hiding which command is undefined. You could raise an issue with the editor.

On the other hand, this leads to a error flooding, when I set the tkiz terminal in gnuplot and omit the word terminal.

Since it seems a quite common typo, now once you type gnuplot, tikz becomes an alias to tikz terminal in the rest of the options. Btw, if you often need this option, you can enable it by default via:

\robExtConfigure{
  add to preset={gnuplot}{
    tikz terminal
  }
}

or by creating your own preset:

\robExtConfigure{
  new preset={gnuplot-tikz}{gnuplot, tikz terminal}
}
tobiasBora commented 6 months ago

Since it seems a quite common typo, now once you type gnuplot, tikz becomes an alias to tikz terminal in the rest of the options

Argg in fact this creates nasty bugs to redefine tikz when elements are nested, i.e. if preset gnuplot has an include command that adds a tikz picture that is cached via cacheTikz and that call the tikz preset which has been redefined… So let's avoid to deal with this monstrosity for now… and just use tikz terminal and not tikz since it is already for the tikz preset… and if you are worried about forgetting the name, just add tikz terminal by default or create a new preset just for that.

It does not display the whole error, because a linebreak,

Ok, I got this error fixed as well… but with a dirty hack since I need also to separate the lines in the log by around 4 newlines otherwise texstudio does not consider them as different errors and just hide them… So the log is less nice, but at least you get nice errors directly in the document:

image

I don't think I can do much better, for better error messages you need to urge texstudio to solve their bugs ^^' Let me know if it works for you, and if you discover nasty side effects I have not considered.

dflvunoooooo commented 6 months ago

Ahah yes, since I had no gnuplot installed on my shell, I was using this code to test if I was indeed getting an error "you don't have gnuplot installed", sorry ^^'

No problem!

Yes LaTeX and texstudio are really anoying. I'm trying to ask here if there is a better solution https://tex.stackexchange.com/questions/705502/message-add-symbol-in-front-of-new-lines-even-if-there-is-a-line-break but the best thing would be for texstudio to parse errors correctly (tried to ask here and I got a link to the github issue texstudio-org/texstudio#1410 and one told me:

Argg in fact this creates nasty bugs to redefine tikz when elements are nested, i.e. if preset gnuplot has an include command that adds a tikz picture that is cached via cacheTikz and that call the tikz preset which has been redefined… So let's avoid to deal with this monstrosity for now…

Texstudio seems to be a pain. I will not complain anymore. Thank you very much for trying so hard! I am still experiencing those nasty bugs. Did you revert to version? I am seeing lots of different errors. Here is one Command \robExtEnvironmentOrigtikzpicture already defined. \end.

tobiasBora commented 6 months ago

I am seeing lots of different errors

Ohhh sorry, I forgot to push the changes ^^' Yes, I also noticed this regression which was introduced when I added tikz as a shortcut for tikz terminal in gnuplot, this was a bad idea as it was erasing the tikz preset in nested gnuplot + cacheTikz settings. This should be fixed in master. Sorry for this poor experience.

dflvunoooooo commented 6 months ago

No problem. Now it is working again. And I see the relevant error messages in Texstudio. Even thos two broken lines. I think we can close this issue then :)

Screenshot_20231222_114537

tobiasBora commented 6 months ago

Great, thanks for your return! (yeah, I wrote a code to fix the broken lines as well)

dflvunoooooo commented 6 months ago

Great work. Thank you for all your work and fast response! :)

dflvunoooooo commented 4 months ago

This might also expand to the python preset. If there is an error in my python code the only error message in the main log is

The file robustExternalize/robExt-BF76F89790065808712AB06EA4CD2D2B.tex already exists.
No need to recompile robustExternalize/robExt-BF76F89790065808712AB06EA4CD2D2B.pdf
(./robustExternalize/robExt-BF76F89790065808712AB06EA4CD2D2B-out.tex)

! LaTeX Error: File `robustExternalize/robExt-BF76F89790065808712AB06EA4CD2D2B.pgf' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: pgf)

Enter file name: 
/home/brian/Daten/Latex/_Problem/robExt python error message/test.tex:41: Emergency stop.
<read *> 

l.41     \end{CacheMeCode}

The corresponding robust-extrernalize log is

Traceback (most recent call last):
  File "/home/brian/Daten/Latex/_Problem/robExt python error message/robustExternalize/robExt-BF76F89790065808712AB06EA4CD2D2B.tex", line 81, in <module>
    finished_with_no_error()
  File "/home/brian/Daten/Latex/_Problem/robExt python error message/robustExternalize/robExt-BF76F89790065808712AB06EA4CD2D2B.tex", line 75, in finished_with_no_error
    Messwerte = pd.read_table(Datei, names=('x', 'y'), sep='\s+')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1289, in read_table
    return _read(filepath_or_buffer, kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 605, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1442, in __init__
    self._engine = self._make_engine(f, self.engine)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 1735, in _make_engine
    self.handles = get_handle(
                   ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pandas/io/common.py", line 856, in get_handle
    handle = open(
             ^^^^^
FileNotFoundError: [Errno 2] Datei oder Verzeichnis nicht gefunden: 'wrong_name.dat'

I am using my custom python matplotlib, if that matters. Here is a mwe:

\documentclass{scrartcl} 

\usepackage{robust-externalize}
\robExtConfigure{
    enable fallback to manual mode,                 % Gibt Warnung aus, falls -shell-escape nicht aktiviert.
    compile in parallel after=4,                    % Beschleunigt das (erstmalige) erzeugen der Grafiken, da parallel generiert.
    add to preset={latex}{                          % │ Erstellt die mittels robust-externalize gecachten Abbildungen mit XeLaTeX.
        use lualatex,                               % │ Liegt hier in der ifXeTex umgebung, damit nur dann auch mit LuaLaTeX erzeugt wird.
    },
    new preset={python matplotlib pgf}{
        python,
        include command is input,
        custom include command={\input{\robExtAddCachePathAndName{\robExtFinalHash.pgf}}},
    },
}
\runHereAndInPreambleOfCachedFiles{
    \usepackage{amsmath}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.18}
}

\begin{filecontents}[overwrite]{name.dat}
    1   2
    2   4
    3   6
\end{filecontents}

\begin{document}
\begin{figure}
    \centering
    \begin{CacheMeCode}{python matplotlib pgf}
        import matplotlib.pyplot as plt
        import matplotlib                                           # ┐ Um die Ausgabe von Latex verarbeitbar zu machen, damit Schriftart usw. stimmt.
        matplotlib.use('pgf')                                       # ┘ Diese Methode nötig, da sonst Optionen übergangen werden.
        import pandas as pd 
        Datei = 'wrong_name.dat'
        Messwerte = pd.read_table(Datei, names=('x', 'y'), sep='\s+')
        plt.plot(Messwerte_abkue["x"], Messwerte_abkue["y"], label='Test')
        plt.savefig(get_filename_from_extension(".pgf"))
    \end{CacheMeCode}
    \caption{\(\mathrm{Number} \text{Number}\)Test Python matplot pgf mit CacheMeCode.}%
    \label{py:testMatplotPGF}
\end{figure}

\end{document}
tobiasBora commented 4 months ago

As I told you, for now python code should not be indented with LaTeX code, otherwise the output is basically really unpredictable. In particular, the code might never run, might produce an error, or might run after the .pdf is produced (which is the case in this example). As the creation of this pdf means "there were no error", the library thinks that everything is good while it is not. Try to remove the spaces before the python code and you will get again a clear error message. I'll try to solve this issue as explained in https://github.com/leo-colisson/robust-externalize/issues/25

dflvunoooooo commented 4 months ago

Oh, I understad. Without indention it is showing the error messages. Sorry to have bothered you!