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

LaTeX document gets built twice when embedded Asymptote code is modified #2237

Closed
ghost opened this issue Aug 9, 2020 · 11 comments
Closed
Labels
enhancement Issue suggests an enhancement external issue Issue with something else than LaTeX-Wokshop

Comments

@ghost
Copy link

ghost commented Aug 9, 2020

Preliminary questions [Required]

Disable all the other extensions except for LaTeX Workshop, and check that you still see this issue. [Required]

You still see this issue?: Yes

Make sure to visit the wiki FAQ before filling an issue.

You visited the wiki?: Yes

If your issue is with compiling a document (not having to do with finding the root file of a project), check first that you can compile manually.

You can compile a TeX document manually?: Yes

Describe the bug [Required]

When I edit some Asymptote code inside a LaTeX document and build it, Latexmk is run twice even when latex-workshop.latex.autoBuild.cleanAndRetry.enabled is set to false.

To Reproduce

Steps to reproduce the behavior:

  1. Create a foo.tex file with the following contents:
\documentclass{article}
\usepackage{asymptote}
\begin{document}
    \begin{asy}
        draw((0,0)--(100,100));
    \end{asy}
\end{document}
  1. Create a latexmkrc file in the same directory with the following contents:
sub asy {return system("asy \"$_[0]\"");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");
  1. Build the document.
  2. Edit the Asymptote code and build it again, either by saving with automatic build enabled or using Ctrl + Alt + B.
  3. Notice that Latexmk is run twice. In the output panel, you can see the first build complete and then the output is cleared and Latexmk is run a second time, which results in a message saying that the targets are up-to-date.

Expected behavior

The document should only be build once, since Latexmk already handles reruns.

Logs [Required]

Please paste the whole log messages here, not parts of ones. The log should start with Initializing LaTeX Workshop. It is very important to identify problems.

LaTeX Workshop Output [Required]

[16:28:31] Initializing LaTeX Workshop.
[16:28:31] Creating PDF file watcher.
[16:28:31] Creating LaTeX Workshop http and websocket server.
[16:28:31] LaTeX Workshop initialized.
[16:28:32] Found root file from active editor: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:32] Root file changed: from undefined to c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:32] Start to find all dependencies.
[16:28:32] Instantiating a new file watcher for c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:32] Creating Bib file watcher.
[16:28:32] Parsing a file and its subfiles: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:32] Parse fls file.
[16:28:32] Fls file found: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.fls
[16:28:32] Parse aux file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.aux
[16:28:32] Server created on 127.0.0.1:55785
[16:28:32] Added to file watcher: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:32] Added to file watcher: c:\Users\zhang\Desktop\Discrete Math HW\test\foo-1.pdf
[16:28:32] LaTeX Workshop version: 8.11.1
[16:28:32] Snippet data loaded.
[16:28:34] Preview PDF file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.pdf
[16:28:34] Handle data type: open
[16:28:34] Handle data type: request_params
[16:28:34] Handle data type: loaded
[16:28:40] BUILD command invoked.
[16:28:40] Found root file from active editor: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:40] Keep using the same root file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex.
[16:28:40] Building root file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:40] Build root file c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:40] Recipe step 1: latexmk, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=c:/Users/zhang/Desktop/Discrete Math HW/test,c:/Users/zhang/Desktop/Discrete Math HW/test/foo
[16:28:40] cwd: c:\Users\zhang\Desktop\Discrete Math HW\test
[16:28:40] LaTeX build process spawned. PID: 24672.
[16:28:41] File watcher - file changed: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:41] Parsing a file and its subfiles: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:41] Parse fls file.
[16:28:41] Fls file found: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.fls
[16:28:41] Parse aux file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.aux
[16:28:41] Auto Build Run is temporarily disabled during a second.
[16:28:44] Found root file from active editor: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:44] Keep using the same root file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex.
[16:28:46] File watcher - file changed: c:\Users\zhang\Desktop\Discrete Math HW\test\foo-1.pdf
[16:28:46] Auto build started detecting the change of a file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo-1.pdf
[16:28:46] BUILD command invoked.
[16:28:46] Building root file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:48] LaTeX log parsed with 0 messages.
[16:28:48] Recipe of length 1 finished. PID: 24672.
[16:28:48] Successfully built c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex.
[16:28:48] Refresh PDF viewer for c:\Users\zhang\Desktop\Discrete Math HW\test\foo.pdf
[16:28:48] Parse fls file.
[16:28:48] Fls file found: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.fls
[16:28:48] Parse aux file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.aux
[16:28:48] Build root file c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:48] Recipe step 1: latexmk, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=c:/Users/zhang/Desktop/Discrete Math HW/test,c:/Users/zhang/Desktop/Discrete Math HW/test/foo
[16:28:48] cwd: c:\Users\zhang\Desktop\Discrete Math HW\test
[16:28:48] LaTeX build process spawned. PID: 19680.
[16:28:48] Preview PDF file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.pdf
[16:28:48] Handle data type: loaded
[16:28:48] Recipe of length 1 finished. PID: 19680.
[16:28:48] Successfully built c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex.
[16:28:50] Found root file from active editor: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex
[16:28:50] Keep using the same root file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo.tex.

Developer Tools Console [Required]

This is the only thing I see in the console:

webviewElement.ts:160 [Embedded Page] PDF 91c45522f82abcd17b959e9d21985848 [1.5 pdfTeX-1.40.21 / TeX] (PDF.js: 2.3.200)
webviewElement.ts:160 [Embedded Page] PDF b31dfe5da87f6c7c21e88cb6c4e56242 [1.5 pdfTeX-1.40.21 / TeX] (PDF.js: 2.3.200)

Screenshots

This is after I modified the Asymptote code and built the document. Notice that it says its up-to-date in the output pane because it's been run a second time.
image

Desktop [Required]

  • OS: Windows 10
  • VS Code version: 1.47.3
  • Extension version: 8.11.1
  • TeX distribution version: TeX Live 2020

Additional questions

Are you using VSCodium?

No

Are you using LaTeX Workshop with VS Code Remote?

No

Additional context

I'm using the default recipe and tools, with automatic retry on build failure disabled. The build only gets run twice when the Asymptote code is modified. If I modify some other part of the document the build only gets run once and I can see the full output.

Here's the contents of foo.aux:

\relax 

And here's foo.fls:

PWD c:/Users/zhang/Desktop/test
INPUT c:/texlive/2020/texmf.cnf
INPUT c:/texlive/2020/texmf-dist/web2c/texmf.cnf
INPUT c:/texlive/2020/texmf-var/web2c/pdftex/pdflatex.fmt
INPUT c:/Users/zhang/Desktop/test/foo.tex
OUTPUT c:/Users/zhang/Desktop/test/foo.log
INPUT c:/texlive/2020/texmf-dist/tex/latex/base/article.cls
INPUT c:/texlive/2020/texmf-dist/tex/latex/base/article.cls
INPUT c:/texlive/2020/texmf-dist/tex/latex/base/size10.clo
INPUT c:/texlive/2020/texmf-dist/tex/latex/base/size10.clo
INPUT c:/texlive/2020/texmf-dist/tex/latex/asymptote/asymptote.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/asymptote/asymptote.sty
INPUT c:/Users/zhang/Desktop/test/foo.pre
INPUT c:/Users/zhang/Desktop/test/foo.pre
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/base/ifthen.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/base/ifthen.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/color.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/color.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics-cfg/color.cfg
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics-cfg/color.cfg
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics-def/pdftex.def
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics-def/pdftex.def
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/graphicx.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/graphicx.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/graphics.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/graphics.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/trig.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics/trig.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
INPUT c:/texlive/2020/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/ifpdf.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/ifpdf.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/ifpdf.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/iftex.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/iftex.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/ifxetex.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/ifxetex.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/iftex/ifxetex.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/catchfile/catchfile.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/catchfile/catchfile.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/catchfile/catchfile.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/infwarerr/infwarerr.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/infwarerr/infwarerr.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/etexcmds/etexcmds.sty
INPUT c:/texlive/2020/texmf-dist/tex/generic/etexcmds/etexcmds.sty
OUTPUT c:/Users/zhang/Desktop/test/foo.pre
INPUT c:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def
INPUT c:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def
INPUT c:/Users/zhang/Desktop/test/foo.aux
INPUT c:/Users/zhang/Desktop/test/foo.aux
OUTPUT c:/Users/zhang/Desktop/test/foo.aux
INPUT c:/texlive/2020/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
INPUT c:/texlive/2020/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
INPUT c:/texlive/2020/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
INPUT c:/texlive/2020/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
INPUT c:/texlive/2020/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
OUTPUT c:/Users/zhang/Desktop/test/foo-1.asy
INPUT c:/Users/zhang/Desktop/test/foo-1.pdf
INPUT c:/Users/zhang/Desktop/test/foo-1.pdf
INPUT c:/Users/zhang/Desktop/test/foo-1.pdf
OUTPUT c:/Users/zhang/Desktop/test/foo.pdf
INPUT c:/Users/zhang/Desktop/test/foo-1.pdf
INPUT c:/texlive/2020/texmf-var/fonts/map/pdftex/updmap/pdftex.map
INPUT c:/Users/zhang/Desktop/test/foo.aux
INPUT c:/texlive/2020/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb
@tamuratak
Copy link
Contributor

This is the cause:

[16:28:46] Auto build started detecting the change of a file: c:\Users\zhang\Desktop\Discrete Math HW\test\foo-1.pdf

I am not sure where foo-1.pdf comes from.

Please paste foo.fls and foo.aux. Thank you for your cooperation.

@ghost
Copy link
Author

ghost commented Aug 10, 2020

@tamuratak Sorry, I forgot to mention that the document is saved in a file named foo.tex. foo-1.pdf is the image produced by Asymptote which gets embedded into the final pdf. I've added foo.fls and foo.aux to my first comment. So what I think is happening is that the extension detected that foo-1.pdf was a dependency, so after Asymptote modified it during the build process the extension saw that the file changed and build the document again.

@tamuratak
Copy link
Contributor

tamuratak commented Aug 10, 2020

A workaround is to adding foo-1.pdf, or "**/*.pdf", to latex-workshop.latex.watch.files.ignore.

See https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexwatchfilesignore

@tamuratak tamuratak added enhancement Issue suggests an enhancement external issue Issue with something else than LaTeX-Wokshop labels Aug 10, 2020
@jlelong
Copy link
Collaborator

jlelong commented Aug 11, 2020

This is because foo-1.pdf is listed as an input file in foo.fls

INPUT c:/Users/zhang/Desktop/test/foo-1.pdf

I would have expected it to be listed as output too because it is generated during compilation but unfortunately such is not the case. I cannot see how we can handle automatically.

@tamuratak
Copy link
Contributor

tamuratak commented Aug 11, 2020

We can exclude INPUT c:/Users/zhang/Desktop/test/foo-1.pdf if there exists a line

OUTPUT c:/Users/zhang/Desktop/test/foo-1.asy

for this case. The suffix, .asy, is the one for Aymptone.

@jlelong
Copy link
Collaborator

jlelong commented Aug 13, 2020

@tamuratak yes we can but it looks like a hack to me.
I think Asymptote should declare the generated .pdf files both as input and output files as the minted package does.
I have filled an issue on vectorgraphics/asymptote#173

@jlelong
Copy link
Collaborator

jlelong commented Aug 24, 2020

This is still under discussion in vectorgraphics/asymptote#173.

From a more general point of view, I suggest to drop all the onChange events occurring during a build and to only keep the onSave events. I think this would also solve #2153. @tamuratak what do you think of this?

@tamuratak
Copy link
Contributor

tamuratak commented Aug 24, 2020

The change on foo-1.pdf is detected by Manager.fileWatcher:

if (this.fileWatcher) {
this.fileWatcher.on('add', (file: string) => this.onWatchingNewFile(file))
this.fileWatcher.on('change', (file: string) => this.onWatchedFileChanged(file))
this.fileWatcher.on('unlink', (file: string) => this.onWatchedFileDeleted(file))
}

I cannot see the difference between onChange and onSave on this issue.

@jlelong
Copy link
Collaborator

jlelong commented Aug 24, 2020

I was referring to latex-workshop.latex.autoBuild.run.

  • The onFileChange value is handled by
    if (this.fileWatcher) {
    this.fileWatcher.on('add', (file: string) => this.onWatchingNewFile(file))
    this.fileWatcher.on('change', (file: string) => this.onWatchedFileChanged(file))
    this.fileWatcher.on('unlink', (file: string) => this.onWatchedFileDeleted(file))
    }
  • Then onSave value is handled by

    LaTeX-Workshop/src/main.ts

    Lines 132 to 148 in 19ab221

    context.subscriptions.push(vscode.workspace.onDidSaveTextDocument( (e: vscode.TextDocument) => {
    if (extension.manager.hasTexId(e.languageId)) {
    extension.linter.lintRootFileIfEnabled()
    extension.structureProvider.refresh()
    extension.structureProvider.update()
    const configuration = vscode.workspace.getConfiguration('latex-workshop')
    if (configuration.get('latex.autoBuild.run') as string === BuildEvents.onSave) {
    if (extension.builder.disableBuildAfterSave) {
    extension.logger.addLogMessage('Auto Build Run is temporarily disabled during a second.')
    return
    }
    extension.logger.addLogMessage(`Auto build started on saving file: ${e.fileName}`)
    extension.commander.build(true)
    }
    }
    }))

@tamuratak
Copy link
Contributor

Thank you. I see.

I don't like making building processes more complicated. It is enough complicated.

@jlelong
Copy link
Collaborator

jlelong commented Aug 25, 2020

I don't like making building processes more complicated.

I tend to agree with this.

Yet, there does not seem to be any easy solution to fix this issue. Since latexmk detects that the second build is useless and does nothing, I think we can close this issue.

There are two workarounds to this issue

  1. Adding foo-1.pdf, or "**/*.pdf", to latex-workshop.latex.watch.files.ignore.
  2. Setting latex-workshop.latex.autoBuild.run to onSave instead of onFileChange.

@jlelong jlelong closed this as completed Aug 25, 2020
Repository owner locked as resolved and limited conversation to collaborators Feb 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Issue suggests an enhancement external issue Issue with something else than LaTeX-Wokshop
Projects
None yet
Development

No branches or pull requests

2 participants