Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asy files produced from a tex file should be marked as input and output files by the -recorder option #173

Closed
jlelong opened this issue Aug 13, 2020 · 11 comments

Comments

@jlelong
Copy link

jlelong commented Aug 13, 2020

This is related to James-Yu/LaTeX-Workshop#2237 (I am a maintainer of the extesion)

Consider a toy foo.tex file

\documentclass{article}
\usepackage{asymptote}
\begin{document}
    \begin{asy}
        draw((0,0)--(100,100));
    \end{asy}
\end{document}

along with the following latexmkrc file

sub asy {return system("asy \"$_[0]\"");}
add_cus_dep("asy","-f","eps",0,"asy");
add_cus_dep("asy","-f","pdf",0,"asy");
add_cus_dep("asy","-f","tex",0,"asy");

The foo.fls files produced by latexmk (actually by the -recorder option of [pdf]latex) lists foo-1.asy as an OUTPUT file and foo-1.pdf as an INPUT file. I think foo-1.pdf should be marked as an OUTPUT file too.

@johncbowman
Copy link
Member

Is this an Asymptote issue or a latexmk issue? Where and how exactly do you want to "mark" asy files as Output files?
A patch or pull request would be welcome.

@jlelong
Copy link
Author

jlelong commented Aug 13, 2020

This is not related to latexmk as the foo.fls file is produced by latex -recorder foo.tex. Excerpt from latex man page

-recorder
    Enable the filename recorder. This leaves a trace of the files opened for input and output in a file with extension .fls.

For instance, the minted package produces .pyg files during compilation which are marked as output and input. Maybe looking at minted.sty could give a hint on how to proceed.

@johncbowman
Copy link
Member

I think there is a misunderstanding here: you need to run [pdf]latex twice: once to produce the .asy file and then a second time,
after running foo-*.asy, to include the generated .eps or .pdf files. This is also the case with the minted.sty package.
If you run latexmk on the following example and change np to np2, the next latexmk run will invoke [pdf]latex twice.
There is nothing to fix here.

\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}{python}
import numpy as np
\end{minted}
\end{document}



@jlelong
Copy link
Author

jlelong commented Aug 16, 2020

I will try to make my point more precise. When running latexmk using the latexmkrc of my first post, which seems to be the recommended way to proceed, the file foo.fls lists

OUTPUT foo-1.asy
INPUT foo-1.pdf

I would expect foo-1.pdf to be marked with OUTPUT also. The difference between asymptote and minted lies in the way the extra files are generated. With minted everything is handled by the package, whereas with asymptote the user has to run asy by hand which is the foo-1.pdf file is not marked as output also by the -recorder option of pdflatex.

I hope my explanation is clearer this time.

@johncbowman
Copy link
Member

johncbowman commented Aug 16, 2020

The whole point of using latexmk is that you do not need to run asy by hand; it does that automatically. I already spent much time looking into minted.sty and manually adding OUTPUT foo-1.pdf to foo.fls only to conclude that this does not (and cannot) reduce the number of latex passes from two to one, as I already explained.

Obviously there is a misunderstanding here. Make sure you have the .latexmkrc file in the current working directory. Don't forget the dot in front of the file name.

@jlelong
Copy link
Author

jlelong commented Aug 17, 2020

Thanks for your answer but it seems I missed my point. First, I would like to emphasize that I am not discussing how to use latexmk, which works perfectly well to generate foo-1.pdf. For sure, there is no way to reduce the number of latex passes and this is not my point either.

I just want to discuss the content of the .fls file as it is used to track the dependencies of LaTeX project to know when to recompile the main .tex file. Excerpt of latexmk man page

       -recorder
              Give the -recorder option with latex and pdflatex.   In  (most)  modern  versions  of
              these  programs,  this  results  in a file of extension .fls containing a list of the
              files that these programs have read and written.  Latexmk will then use this file  to
              improve  its  detection  of  source files and generated files after a run of latex or
              pdflatex.  This is the default setting of latexmk, unless overridden in  an  initial-
              ization file.

As I have already said, the file foo-1.pdf being generated during the compilation process, I would expect it to be marked as an output file and not only as an input one. The difference between asymptote and minted lies in the way the extra files are generated. With asymptote, foo-1.pdf is generated when latexmk calls asy while with minted, python is directly called by the latex process thanks to the -shell-escape flag. Because foo-1.pdf is not generated directly by the latex process but by calling the asy program manually between two latex passes (even though it is done automatically thanks to latexmk), the latex compiler cannot be aware that foo-1.pdf is actually generated during the compilation.

My whole point is to improve dependency detection when using asymptote to monitor when compiling is needed. See James-Yu/LaTeX-Workshop#2237. I do hope I made my point clearer this time.

@johncbowman
Copy link
Member

It would really help if you can be explicit about what exactly you want to change.
Do you want asy to manually append "OUTPUT foo-1.pdf" to foo.fls even though another program (latex) is responsible for generating this file? I can add a patch to implement this hack, but it isn't clear if this is really what you want.

For security reasons, I don't recommend using -shell-escape.

@jlelong
Copy link
Author

jlelong commented Aug 24, 2020

Do you want asy to manually append "OUTPUT foo-1.pdf" to foo.fls even though another program (latex) is responsible for generating this file?

Yes, I would like to see foo-.pdf listed as an output file in foo.fls and not only as an input file as it is now.
Even though, asy is responsible for generating foo-1.pdf, it is an intermediate file.

@johncbowman
Copy link
Member

Here's a hack to asy-latex.dtx that puts the dependency information you want in a file foo.fls_asy; you'll have to read that file as well as foo.fls:

flsHack.txt

@jlelong
Copy link
Author

jlelong commented Aug 25, 2020

Thanks for your efforts but I do not think it really helps because

  1. An extra file has to be parsed
  2. The .fls is normally only generated when using -recorder (which latexmk always does)
  3. It generates yet another temporary file.

@HumHongeKamyaab
Copy link

#183 may be related with this. I would request users here to please have a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants