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

% !TEX program = latexmk -xelatex -synctex=1 doesn't work #4347

Closed
4 tasks done
SamuelMarks opened this issue Aug 26, 2024 · 11 comments · Fixed by #4385
Closed
4 tasks done

% !TEX program = latexmk -xelatex -synctex=1 doesn't work #4347

SamuelMarks opened this issue Aug 26, 2024 · 11 comments · Fixed by #4385

Comments

@SamuelMarks
Copy link

Pre-checks*

  • The issue has not been reported in this repository.
  • The issue remains after disabling all other extensions and restarting Visual Studio Code.
  • The FAQ cannot address the issue.
  • The issue is not related to compiling a document, or the document can be successfully compiled in the OS terminal but not in Visual Studio Code with this extension.

Environment*

  • Operating System: Windows 11 23H2
  • Visual Studio Code Version: 1.92.2
  • LaTeX Workshop Version: 10.1.0
  • TeX Distribution Version: MiKTeX 4.19

The Issue*

latexmk not executed properly with magic string, get error as if XeLaTeX:

MiKTeX\tex/latex/fontspec\fontspec.sty:101: Fatal Package fontspec Error: The fontspec package requires either XeTeX or
(fontspec) LuaTeX.
(fontspec)
(fontspec) You must change your typesetting engine to,
(fontspec) e.g., "xelatex" or "lualatex" instead of
(fontspec) "latex" or "pdflatex".

Reproduction Steps

  1. Toggle this property https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexbuildforcerecipeusage
  2. Create two files, one that uses XeLaTeX and a bib
  3. Add % !TEX program = xelatex; note that it works without error, but bibliography not added
  4. Add % !TEX program = latexmk -xelatex -synctex=1 and note that it doesn't work

Expected Behavior

What were you expecting to see? Include any relevant examples or documentation links.

  • should build without error and incorporate bibliography
  • tested this command on the CLI (Windows Command Prompt) and it worked without err

Logs

LaTeX Workshop Output*

Please paste the whole log messages below, not parts of ones. The log should start with New log placeholder %WS1% registered.


Developer Tools Console

Please paste the whole log messages below, not parts of ones. This console logs can sometimes be very important in many cases. To access the log, click Help -> Toggle Developer Tools -> Console.

Anything Else?

The alternative recipe solution does work:

"latex-workshop.latex.recipes": [
        {
            "name": "pdflatex",
            "tools": [
              "pdflatex"
            ]
        },
        {
            "name": "xelatexlatexmk",
            "tools": [
              "xelatexlatexmk"
            ]
        }
    ],
    "latex-workshop.latex.tools": [
        {
            "name": "xelatexlatexmk",
            "command": "latexmk",
            "args": [
                "-xelatex",
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOC%"
            ]
        },
@James-Yu
Copy link
Owner

@SamuelMarks
Copy link
Author

@James-Yu !TEX options didn't seem to work for this use-case.

I have a single tex file and a single bib file, and here is my magic:

% !TEX root = myfile.tex
% !TEX program = latexmk
% !TEX options = -xelatex -synctex=1 -interaction=nonstopmode -file-line-error "%DOC%"

It does work when using the aforementioned recipe.

Checking the logs I see:

Initial Win CP for (console input, console output, system): (CP437, CP65001, CP1252)
I changed them all to CP1252
Rc files read:
  NONE
Latexmk: This is Latexmk, John Collins, 7 Apr. 2024. Version 4.85.
No specific requests made, so using default for latexmk.
No existing .aux file, so I'll make a simple one, and require run of *latex.
Latexmk: applying rule 'latex'...
Rule 'latex':  Reasons for rerun
Category 'other':
  Rerun of 'latex' forced or previously required:
    Reason or flag: 'Initial setup'

------------
Run number 1 of rule 'latex'
------------
------------
Running 'latex  --max-print-line=10000 -recorder  "myfile.tex"'
------------
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (MiKTeX 24.4) (preloaded format=latex.fmt)
 restricted \write18 enabled.
entering extended mode
(myfile.tex
LaTeX2e <2024-06-01> patch level 2
L3 programming layer <2024-07-20>

LaTeX Warning: Writing or overwriting file `myfile.xmpdata'.


(myfile.cls
Document Class: myfile template
(MiKTeX\tex/latex/extsizes\extarticle.cls
Document Class: extarticle 1996/10/08 v1.0 Non Standard LaTeX document class
(MiKTeX\tex/latex/extsizes\size9.clo) (MiKTeX\tex/latex/base\exscale.sty)) (MiKTeX\tex/latex/fontspec\fontspec.sty (MiKTeX\tex/latex/l3packages/xparse\xparse.sty (MiKTeX\tex/latex/l3kernel\expl3.sty (MiKTeX\tex/latex/l3backend\l3backend-dvips.def)))

! Fatal Package fontspec Error: The fontspec package requires either XeTeX or
(fontspec)                      LuaTeX.
(fontspec)                      
(fontspec)                      You must change your typesetting engine to,
(fontspec)                      e.g., "xelatex" or "lualatex" instead of
(fontspec)                      "latex" or "pdflatex".

Type <return> to continue.
 ...                                              
                                                  
l.101 \msg_fatal:nn {fontspec} {cannot-use-pdftex}
                                                  
? 

Any insights would be appreciated. Thanks.

@James-Yu
Copy link
Owner

Please provide extension log.

@SamuelMarks
Copy link
Author

@James-Yu Sure thing. After closing VS code, cleaning all the auxillary files, commenting out "latex-workshop.latex.recipe.default" and setting "latex-workshop.latex.build.forceRecipeUsage": false:

[21:31:02.802][Logger] New log placeholder %WS1% registered for my_absolute_dir_path .
[21:31:02.802][Extension] Initializing LaTeX Workshop.
[21:31:02.984][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_LATEX: ""
[21:31:02.984][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_PATH: "docker"
[21:31:03.077][Server] Creating LaTeX Workshop http and websocket server.
[21:31:03.186][Format][Bib] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[21:31:03.263][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":61214} .
[21:31:03.275][Extension] Extension root: C:%HOMEPATH%\.vscode\extensions\james-yu.latex-workshop-10.1.0
[21:31:03.276][Extension] $PATH: C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Microsoft\jdk-11.0.24.8-hotspot\bin;C:\usr\Ruby32-x64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\usr\msys64;C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Microsoft VS Code\bin;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\usr\Java\jdk-22\binC:\usr\LLVM\bin;
[21:31:03.277][Extension] $SHELL: undefined
[21:31:03.277][Extension] $LANG: undefined
[21:31:03.277][Extension] $LC_ALL: undefined
[21:31:03.277][Extension] process.platform: win32
[21:31:03.278][Extension] process.arch: x64
[21:31:03.278][Extension] vscode.env.appName: Visual Studio Code
[21:31:03.278][Extension] vscode.env.remoteName: undefined
[21:31:03.278][Extension] vscode.env.uiKind: 1
[21:31:03.281][Config] latex-workshop.latex.recipes: [{"name":"pdflatex","tools":["pdflatex"]},{"name":"xelatexlatexmk","tools":["xelatexlatexmk"]}] .
[21:31:03.283][Config] latex-workshop.latex.tools: [{"name":"xelatexlatexmk","command":"latexmk","args":["-xelatex","-synctex=1","-interaction=nonstopmode","-file-line-error","%DOC%"]},{"name":"latexmk","command":"latexmk","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","-outdir=%OUTDIR%","%DOC%"],"env":{}},{"name":"lualatexmk","command":"latexmk","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","-lualatex","-outdir=%OUTDIR%","%DOC%"],"env":{}},{"name":"xelatexmk","command":"latexmk","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","-xelatex","-outdir=%OUTDIR%","%DOC%"],"env":{}},{"name":"latexmk_rconly","command":"latexmk","args":["%DOC%"],"env":{}},{"name":"pdflatex","command":"pdflatex","args":["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOC%"],"env":{}},{"name":"bibtex","command":"bibtex","args":["%DOCFILE%"],"env":{}},{"name":"rnw2tex","command":"Rscript","args":["-e","knitr::opts_knit$set(concordance = TRUE); knitr::knit('%DOCFILE_EXT%')"],"env":{}},{"name":"jnw2tex","command":"julia","args":["-e","using Weave; weave(\"%DOC_EXT%\", doctype=\"tex\")"],"env":{}},{"name":"jnw2texminted","command":"julia","args":["-e","using Weave; weave(\"%DOC_EXT%\", doctype=\"texminted\")"],"env":{}},{"name":"pnw2tex","command":"pweave","args":["-f","tex","%DOC_EXT%"],"env":{}},{"name":"pnw2texminted","command":"pweave","args":["-f","texminted","%DOC_EXT%"],"env":{}},{"name":"tectonic","command":"tectonic","args":["--synctex","--keep-logs","%DOC%.tex"],"env":{}}] .
[21:31:03.284][Config] latex-workshop.latex.build.forceRecipeUsage: false .
[21:31:03.348][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{","}"]
[21:31:03.350][Root] Current workspace folders: ["file:///my_absolute_dir_path"]
[21:31:03.351][Root] Found magic root %WS1%\myfile.tex
[21:31:03.351][Extension] LaTeX Workshop initialized.
[21:31:03.454][Server] valdOrigin is http://127.0.0.1:61214
[21:31:03.490][Root] Found looped magic root %WS1%\myfile.tex .
[21:31:03.490][Root] Root file changed: from %WS1%\myfile.tex to %WS1%\myfile.tex, langID latex . Refresh dependencies
[21:31:03.490][Event] ROOT_FILE_CHANGED: "myfile.tex"
[21:31:03.491][Cacher][Watcher] Reset.
[21:31:03.491][Cacher][Watcher] Reset.
[21:31:03.493][Cacher] Adding %WS1%\myfile.tex .
[21:31:03.494][Cacher][Watcher] Watched %WS1%\myfile.tex with a new .* watcher on %WS1% .
[21:31:03.494][Event] FILE_WATCHED: "myfile.tex"
[21:31:03.496][Cacher] Caching %WS1%\myfile.tex .
[21:31:03.497][Event] ROOT_FILE_SEARCHED
[21:31:03.676][Cacher] Updated inputs of %WS1%\myfile.tex .
[21:31:03.676][Cacher] Parse LaTeX AST: %WS1%\myfile.tex .
[21:31:03.808][Cacher] Parsed LaTeX AST in 131.84 ms: %WS1%\myfile.tex .
[21:31:03.809][File] Calling kpsewhich to resolve myfile.cls .
[21:31:04.672][File] kpsewhich returned with './myfile.cls'.
[21:31:04.678][File] Calling kpsewhich to resolve -format=.bib \jobname.bib .
[21:31:05.026][File] kpsewhich returned with non-zero code 1.
[21:31:05.027][Cacher] Updated elements in 1218.05 ms: %WS1%\myfile.tex .
[21:31:05.027][Event] FILE_PARSED: "myfile.tex"
[21:31:05.028][Structure] Structure force updated with 0 root sections for %WS1%\myfile.tex .
[21:31:05.029][Event] STRUCTURE_UPDATED
[21:31:09.509][Commander] SHOWLOG command invoked: compiler
[21:31:11.341][Event] STRUCTURE_UPDATED
[21:31:13.271][Extension] onDidSaveTextDocument triggered: file:///myfile.tex
[21:31:13.345][Cacher][Watcher] "change" emitted on %WS1%\myfile.tex.
[21:31:13.345][Cacher] Caching %WS1%\myfile.tex .
[21:31:13.346][Build] Auto build started detecting the change of a file: %WS1%\myfile.tex .
[21:31:13.346][Event] AUTO_BUILD_INITIATED: {"type":"onFileChange","file":"myfile.tex"}
[21:31:13.346][Build] The document of the active editor: file:///myfile.tex
[21:31:13.346][Build] The languageId of the document: latex
[21:31:13.346][Build] Building root file: %WS1%\myfile.tex
[21:31:13.346][Build][Recipe] Build root file %WS1%\myfile.tex
[21:31:13.347][Event] FILE_CHANGED: "myfile.tex"
[21:31:13.348][Build][Recipe] Found TeX program by magic comment: latexmk.
[21:31:13.348][Build][Recipe] Found TeX options by magic comment: -xelatex -synctex=1 -interaction=nonstopmode -file-line-error "%DOC%".
[21:31:13.759][Build][Recipe] `pdflatex` is provided by MiKTeX.
[21:31:13.759][Build][Recipe] outDir: my_absolute_dir_path .
[21:31:13.760][Build] Recipe step 1 The command is latexmk:["--max-print-line=10000","-xelatex -synctex=1 -interaction=nonstopmode -file-line-error \"myfile\""].
[21:31:13.760][Build] env: undefined
[21:31:13.760][Build] root: %WS1%\myfile.tex
[21:31:13.761][Build] cwd: %WS1%
[21:31:13.767][Build] LaTeX build process spawned with PID 8780.
[21:31:13.769][Cacher] Updated inputs of %WS1%\myfile.tex .
[21:31:13.769][Cacher] Parse LaTeX AST: %WS1%\myfile.tex .
[21:31:13.809][Cacher] Parsed LaTeX AST in 40.36 ms: %WS1%\myfile.tex .
[21:31:13.810][File] kpsewhich cache hit on myfile.cls: ./myfile.cls .
[21:31:13.815][File] Calling kpsewhich to resolve -format=.bib \jobname.bib .
[21:31:14.166][File] kpsewhich returned with non-zero code 1.
[21:31:14.167][Cacher] Updated elements in 357.08 ms: %WS1%\myfile.tex .
[21:31:14.167][Event] FILE_PARSED: "myfile.tex"
[21:31:14.168][Structure] Structure force updated with 5 root sections for %WS1%\myfile.tex .
[21:31:14.168][Event] STRUCTURE_UPDATED

Then the LaTeX compiler output:

Initial Win CP for (console input, console output, system): (CP437, CP65001, CP1252)
I changed them all to CP1252
Rc files read:
  NONE
Latexmk: This is Latexmk, John Collins, 7 Apr. 2024. Version 4.85.
No specific requests made, so using default for latexmk.
No existing .aux file, so I'll make a simple one, and require run of *latex.
Latexmk: applying rule 'latex'...
Rule 'latex':  Reasons for rerun
Category 'other':
  Rerun of 'latex' forced or previously required:
    Reason or flag: 'Initial setup'

------------
Run number 1 of rule 'latex'
------------
------------
Running 'latex  --max-print-line=10000 -recorder  "myfile.tex"'
------------
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (MiKTeX 24.4) (preloaded format=latex.fmt)
 restricted \write18 enabled.
entering extended mode
(myfile.tex
LaTeX2e <2024-06-01> patch level 2
L3 programming layer <2024-07-20>

LaTeX Warning: Writing or overwriting file `myfile.xmpdata'.


(myfile.cls
Document Class: myfile template
(C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\tex/latex/extsizes\extarticle.cls
Document Class: extarticle 1996/10/08 v1.0 Non Standard LaTeX document class
(C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\tex/latex/extsizes\size9.clo) (C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\tex/latex/base\exscale.sty)) (C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\tex/latex/fontspec\fontspec.sty (C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\tex/latex/l3packages/xparse\xparse.sty (C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\tex/latex/l3kernel\expl3.sty (C:%HOMEPATH%\AppData\Local\Programs\MiKTeX\tex/latex/l3backend\l3backend-dvips.def)))

! Fatal Package fontspec Error: The fontspec package requires either XeTeX or
(fontspec)                      LuaTeX.
(fontspec)                      
(fontspec)                      You must change your typesetting engine to,
(fontspec)                      e.g., "xelatex" or "lualatex" instead of
(fontspec)                      "latex" or "pdflatex".

Type <return> to continue.
 ...                                              
                                                  
l.101 \msg_fatal:nn {fontspec} {cannot-use-pdftex}
                                                  
? 

@James-Yu
Copy link
Owner

[21:31:13.760][Build] Recipe step 1 The command is latexmk:["--max-print-line=10000","-xelatex -synctex=1 -interaction=nonstopmode -file-line-error \"myfile\""].

Will check.

@James-Yu James-Yu reopened this Aug 30, 2024
@James-Yu
Copy link
Owner

87ea37e should fix the issue. Will publish soon.

James-Yu added a commit that referenced this issue Aug 30, 2024
@SamuelMarks
Copy link
Author

Great that worked, thanks @James-Yu

@SamuelMarks
Copy link
Author

@James-Yu Not sure if you changed something in the past fortnight, but the issue is recurring with VS Code 1.93.0 and LaTeX Workshop 10.3.2:

! Fatal Package fontspec Error: The fontspec package requires either XeTeX or
(fontspec)                      LuaTeX.
(fontspec)                      
(fontspec)                      You must change your typesetting engine to,
(fontspec)                      e.g., "xelatex" or "lualatex" instead of
(fontspec)                      "latex" or "pdflatex".

@James-Yu
Copy link
Owner

That's a local issue unfortunately:

image

@James-Yu
Copy link
Owner

Just double check, are you using MikTeX? Can you try out TeXLive on Windows?

@SamuelMarks
Copy link
Author

Was using MikTeX, yes. Removed that and installed TinyTeX (379MB; after installing all 44 additional packages that I use; fortunately had ~38 listed already in my README).

Seems to work now without err. Both my main LaTeX and my smaller XeLaTeX document both build without issue in different [concurrently open] VS Code windows.

@James-Yu James-Yu reopened this Sep 15, 2024
James-Yu added a commit that referenced this issue Sep 15, 2024
Fix #4347 max-print-line should be added to string when magic tex arg is present
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants
@SamuelMarks @James-Yu and others