vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

Why does inlineimage delete the main file's aux file? #420

Closed user202729 closed 5 months ago

user202729 commented 5 months ago

https://github.com/vectorgraphics/asymptote/blob/dd4b63cc1f7cf0c9bdb716db9963b4a0de8e7d27/picture.cc#L385-L390

As far as I can see, deleting the AUX file is inefficient (LaTeX would need to rerun), so we would like to avoid that as much as possible.

So,


Update: the inlineimage one was first added in 2841f55449b6127d64dd69deea8b046ccc0741a9 and the inlinetex one was first added in 9f0071ef25bc9ee8650f0a9cb947e8b32930f366 .

Update: Okay, the point is that the preexisting AUX file may interfere with the standalone Asymptote compilation. Good point. I'll think what can be done about this. (In the case where asydir or asylatexdir is not the current directory then I think there's a simpler solution)

user202729 commented 5 months ago

Actually the point is that the jobname is customized to be the same of the main file...? But looks like the feature is somewhat broken anyway.

Try compiling the following file:

\documentclass{article}
\usepackage{asymptote}
\begin{document}
123
\begin{asy}
    label("[\jobname]");
\end{asy}

\end{document}

Expected behavior: the [ and the ] is visible.

Actual behavior: they're truncated.

Deleting the whole thing might be a reasonable option.

diff --git a/picture.cc b/picture.cc
index 65c72cbc..4ca86284 100644
--- a/picture.cc
+++ b/picture.cc
@@ -381,20 +381,6 @@ void texinit()
   } else {
     if(!dir.empty())
       cmd.push_back("-output-directory="+dir);
-    string jobname="texput";
-    if(getSetting<bool>("inlineimage") || getSetting<bool>("inlinetex")) {
-      string name=stripDir(stripExt((outname())));
-      size_t pos=name.rfind("-");
-      if(pos < string::npos) {
-        name=stripExt(name).substr(0,pos);
-        unlink((name+".aux").c_str());
-        jobname=name.substr(0,pos);
-        cmd.push_back("-jobname="+jobname);
-#ifdef __MSDOS__
-        cmd.push_back("NUL"); // For MikTeX
-#endif
-      }
-    }
     cmd.push_back("\\scrollmode");
   }

(This way if there happens to be a file named texput.aux then there's a problem. But we can just set the jobname to some uniquely-named file to avoid problems...?)

johncbowman commented 5 months ago

Indeed, the commit message

In inlinetex mode, avoid interference from pre-existing aux file.

answers your question. We don't want to clutter up the working directory with other file prefixes.

Instead of accessing the volatile symbol \jobname, the user should do this to obtain the desired result:

\begin{asy}
    label("["+defaultfilename+"]");
\end{asy}
user202729 commented 5 months ago

Instead of accessing the volatile symbol \jobname, the user should do this to obtain the desired result:

I see. In that case my concern (that jobname must be changed in order to make the values in the measure phase be the same as the actual run) was not a problem

We don't want to clutter up the working directory with other file prefixes.

This is actually not a problem. Starting from a.tex contains

%! TEX program = pdflatex
\documentclass{article}
\usepackage{asymptote}
\begin{document}
123
\begin{asy}
    label("45");
\end{asy}

\end{document}

and type latexmk, the following files are generated, regardless whether the proposed changes are done:

$ ls
a-1.asy  a-1.pdf  a.aux  a.fdb_latexmk  a.fls  a.log  a.pdf  a.pre  a.tex

In other words, the clean-up appears to be done correctly. So it's not a problem.

Still, it feels like a good idea to randomize the jobname -- just in case there are multiple parallel runs of asy in the same directory.

An alternative is to specify -output-directory to be a temporarily-created directory. Then no clutter of current directory, and clean-up is easy.

I think implementing the proposed changes would be a good idea.