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

gnuplot conversion adds tabs as ^^I #16

Closed dflvunoooooo closed 7 months ago

dflvunoooooo commented 7 months ago

If gnuplot code is run with the CacheMeCode environment, the tabs in the gnuplot code are converted to ^^I in the gnuplot code tex file. If run without robust-externalize, those tabs are deleted and replaced with one space. Here is an example:

\documentclass{scrreport}

\usepackage{robust-externalize}
\setPlaceholder*{__ROBEXT_LATEX_ENGINE__}{xelatex}  % Für das robustExternalize-Paket.
\runHereAndInPreambleOfCachedFiles{
    \usepackage{gnuplottex}
    \usepackage{gnuplot-lua-tikz}           
}

\begin{document}

\begin{figure}
    \centering  
    \begin{CacheMeCode}{gnuplot, tikz}
       plot cos(x)              # This is a comment seperated with 4 tabs.    
    \end{CacheMeCode}
\end{figure}

\begin{figure}
    \begin{gnuplot}[terminal=tikz]
        plot cos(x)             # This is a comment seperated with 4 tabs.
    \end{gnuplot}
\end{figure}

\end{document}

Edit: Typo in code.

tobiasBora commented 7 months ago

Ahhh ok, so it seems to be a bug of xelatex (lualatex and pdflatex does not have this problem, you might want to use it meanwhile). I will try to investigate why…

dflvunoooooo commented 7 months ago

Oh, I didn't check that, sorry!

tobiasBora commented 7 months ago

Well, this is still a valid remark, thanks ^^

tobiasBora commented 7 months ago

I created a question here, hopefully someone knows how to solve it.

dflvunoooooo commented 7 months ago

I am having a similar error with pdflatex. Compiled with pdflatex. In the robust-externalize log it says:

\boxRobExt=\box66

! You can't use `macro parameter character #' in restricted horizontal mode.
l.15          plot cos(x)^^I^^I^^I^^I#
                                       This is a comment seperated with 4 tabs.

And in the main log:

Source saved in robustExternalize/robExt-259F57E50F3F7B5B3CD606BF49601943.tex.
[robExt]We will start the compilationusing: cd robustExternalize/ && xelatex -h
alt-on-error "robExt-259F57E50F3F7B5B3CD606BF49601943.tex".
runsystem(cd robustExternalize/ && xelatex -halt-on-error "robExt-259F57E50F3F7
B5B3CD606BF49601943.tex")...executed.

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

Type <return> to continue.
 ...                                              

l.16     \end{CacheMeCode}

LaTeX does not know anything more about this error, sorry.

Compiled with xelatex. The robust-externalize log:

\writeRobExt=\write5
\openout5 = `robExt-04F1D9403B24AC2CEC9BAD0282ACE14E-out.tex'.

\boxRobExt=\box66

! You can't use `macro parameter character #' in restricted horizontal mode.
l.15          plot cos(x)^^I^^I^^I^^I#
                                       This is a comment seperated with 4 tabs.

The main log:

Source saved in robustExternalize/robExt-04F1D9403B24AC2CEC9BAD0282ACE14E.tex.
[robExt]We will start the compilationusing: cd robustExternalize/ && xelatex -h
alt-on-error "robExt-04F1D9403B24AC2CEC9BAD0282ACE14E.tex".
runsystem(cd robustExternalize/ && xelatex -halt-on-error "robExt-04F1D9403B24A
C2CEC9BAD0282ACE14E.tex")...executed.

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

Type <return> to continue.
 ...                                              

l.16     \end{CacheMeCode}

LaTeX does not know anything more about this error, sorry.

Looks almost identical.

tobiasBora commented 7 months ago

So wait, with xelatex I managed to get it work by compiling with the -8bit option as reported in https://tex.stackexchange.com/questions/264461/xelatex-minted-code-block-represents-tabs-as-i :

xelatex -8bit -shell-escape test

(you might want to try --enable-8bit-chars if it fails)

More precisely this file:

%%%%%%%%%%%%%%%%%%%%%%%                 Klassen-Optionen
\documentclass{scrreport}

\usepackage{amsmath}
\usepackage{tikz}

%% Generate the .sty file with:
% ## First, gnuplot does not come with lua/tikz by default, you can get it with:
% $ nix-shell -p '(gnuplot.override { withLua = true; })'
% ## Then, you need to generate the .sty file with:
% $ gnuplot -e "set terminal tikz createstyle"
\usepackage{gnuplot-lua-tikz}

\usepackage{robust-externalize}

%%%%%%%%%%%%%%%%%%%%%%%                 Beginn des eigentlichen Dokuments
\begin{document}

\begin{figure}
  \centering  
  \begin{CacheMeCode}{gnuplot, tikz terminal}
    plot cos(x)             # This is a comment seperated with 4 tabs.    
  \end{CacheMeCode}
\end{figure}

\end{document}
dflvunoooooo commented 7 months ago

Interesting. I can confirm. Your code with the -8bit option is working. The --enable-8bit-chars option still fails. As well as my code.

Edit: But it still fails with the \runHereAndInPreambleOfCachedFiles{…} option.

dflvunoooooo commented 7 months ago

Your code compiled with the -8bit option does even work, if \setPlaceholder*{__ROBEXT_LATEX_ENGINE__}{xelatex}. is added.

tobiasBora commented 7 months ago

I’m a bit lost, first tikz should not be used with gnuplot, I think you meant tikz terminal. I also tried to compile your code with xelatex -8bit foo.tex and pdflatex -8bit foo.tex and both of them work. Here is the exact file I am using:

\documentclass{scrreport}

\usepackage{robust-externalize}
\setPlaceholder*{__ROBEXT_LATEX_ENGINE__}{xelatex}  % Für das robustExternalize-Paket.
\runHereAndInPreambleOfCachedFiles{
    \usepackage{gnuplottex}
    \usepackage{gnuplot-lua-tikz}           
}

\begin{document}

\begin{figure}
    \centering  
    \begin{CacheMeCode}{gnuplot, tikz terminal}
       plot cos(x)              # This is a comment seperated with 4 tabs.    
    \end{CacheMeCode}
\end{figure}

\begin{figure}
    \begin{gnuplot}[terminal=tikz]
        plot cos(x)             # This is a comment seperated with 4 tabs.
    \end{gnuplot}
\end{figure}

\end{document}

If it fails for you, can you copy/paste exactly the file you are using and the whole compilation command?

dflvunoooooo commented 7 months ago

I don't know what I did wrong. Your code works (though the gnuplottex figure does not work, but not relevant here), with and without the \runHereAndInPreambleOfCachedFiles{…} command, sorry. So the -8bit option does the trick.

Edit: Found the gnuplottex problem. There are no spaces allowed in the filename, otherwise gnuplottex will not find its file, because somewhere "" get added to one file. But still irrelevant for this issue.

tobiasBora commented 7 months ago

Ok cool. If you find other edge cases where this fails, please reopen.

tobiasBora commented 7 months ago

Ok cool, I just added a section in the doc explaining this edge case as discussed in https://tex.stackexchange.com/questions/14771/tabs-in-output-file-written-by-xelatex-and-pdflatex-are-different. After googling for a bit, seems like it is the only solution (beside turning tabs into space in your editor directly :-P ).

tobiasBora commented 6 months ago

So beside the -8bit option, you can also follow egreg's advice:

The strategy is very simple: never use TAB when dealing with TeX. Reserve the TAB key to trigger autocompletion and your life will be happier.

In TeXstudio, you can change this behavior via these two options:

Options > Configure TeXstudio > Editor > Replace indentation tabs with spaces
Options > Configure TeXstudio > Editor > Replace tabs in text with spaces
dflvunoooooo commented 6 months ago

Ok cool, I just added a section in the doc explaining this edge case as discussed in https://tex.stackexchange.com/questions/14771/tabs-in-output-file-written-by-xelatex-and-pdflatex-are-different. After googling for a bit, seems like it is the only solution (beside turning tabs into space in your editor directly :-P ).

I will, thank you. Just to clarify, gnuplot itself doesn't care about indention, be they tabs or spaces. Only the conversion from tabs to ^^I is the problem.

dflvunoooooo commented 6 months ago

So beside the -8bit option, you can also follow egreg's advice:

The strategy is very simple: never use TAB when dealing with TeX. Reserve the TAB key to trigger autocompletion and your life will be happier.

In TeXstudio, you can change this behavior via these two options:

Options > Configure TeXstudio > Editor > Replace indentation tabs with spaces
Options > Configure TeXstudio > Editor > Replace tabs in text with spaces

Yes, that works, thank you :)

tobiasBora commented 6 months ago

I will, thank you. Just to clarify, gnuplot itself doesn't care about indention, be they tabs or spaces. Only the conversion from tabs to ^^I is the problem.

Yeah, I also realized that, but I was initially confused because this bug is not present in pdflatex, so gnuplot was actually receiving spaces. I just fixed the doc.