Closed iwan1510 closed 2 years ago
The is correct, when set to auto
, it will try latexmk
first, and then custom
.
What does your build logs suggest? It's always using the custom toolchain?
I think so. I have to check the build log, but yesterday I did a simple experiment. I put the command \usepackage{tgpagella} to change the document font. This (AFAIK) will only work with pdflatex. If I explicitly specify the latexmk toolchain, the document will compile correctly (ie., using the TeX Gyre Pagella font). However, if I use the auto toolchain, xelatex is always used (ie., the custom toolchain) and the document is compiled using the CM font instead.
We just read the exit code of the command and use that as a metric of failure.
You could try adding fontspec
(via \includepackage{fontspec}
) which should throw an error when compiling with pdflatex
?
I'm not sure if this test will work. As I said, the custom toolchain (in my case that means xelatex) seems to be run first. So if I add that package, the document will compile correctly since it is compiled using xelatex. I honestly don't know if this is because the software have tried latexmk (ie., pdflatex) first, failed, then switched to custom. I doubt this, though, since even if I don't add any xelatex-specific package the document is always compiled with xelatex. If the latexmk is favoured, then such a document should have been compiled with pdflatex. An example is the following bare-bones LaTeX source code. It should not generate any errors with pdflatex (i.e., latexmk should not fail), but the document seems to still be compiled using xelatex instead of pdflatex.
Please share your package settings
Will do. But forgive me for asking: how best should I do that? Make a screen shot? Sorry, I'm new at Atom and perhaps I'm missing the obvious.
Screenshot, or config.cson
. Look under the key atom-latex
.
Here's a screenshot of the (I think) relevant section of the package setting:
Here's the content of the config.cson under the key atom-latex:
"atom-latex": compiler: "xelatex" custom_toolchain: "%TEX %ARG %DOC && %TEX %ARG %DOC" focus_viewer: true
I hope these are correct.
I might have been a bit misleading - auto
doesn't run latexmk
and then try the second toolchain
but rather checks if latexmk
exists, and can run (needs perl
).
Sorry for the confusion.
For the matter of auto
falling back to xelatex
- are you using a .latexcfg
with a toolchain
key? This will override the auto
setting.
I'm not sure about the .latexcfg
file. Where do I find it? I never create the file on purpose, but perhaps it exists somewhere.
Then it probably doesn't exist ;-) https://github.com/ashthespy/Atom-LaTeX#-set-per-project-latex-toolchain
Just to confirm, when you manually switch from auto
to latexmk
the file builds with latekxmk
?
Yes, if I specifically choose latexmk
then the file is compiled using latexmk
(and, correspondingly, pdflatex
)
Can you add a debug statements in builder.coffee#L152-L162
setCmds: ->
@latex.manager.loadLocalCfg()
if @latex.manager.config?.toolchain
@custom_toolchain(@latex.manager.config.toolchain)
console.log "cfg:", @cmds
else if atom.config.get('atom-latex.toolchain') == 'auto'
if !@latexmk_toolchain()
@custom_toolchain()
console.log "Auto:", @cmds
else if atom.config.get('atom-latex.toolchain') == 'latexmk toolchain'
@latexmk_toolchain()
console.log "latexmk :", @cmds
else if atom.config.get('atom-latex.toolchain') == 'custom toolchain'
@custom_toolchain()
console.log "custom :", @cmds
This can be done by going to the Atom-Latex package page, and then clicking "View Code" editing, and then reloading your test document window with Ctr
+Shift
+F5
.
Then share what you see in the dev console for auto
and latexmk
I hope these are what you had in mind:
builder.coffee:160 Auto: (2) ["xelatex -synctex=1 -interaction=nonstopmode -file-line-error test", "xelatex -synctex=1 -interaction=nonstopmode -file-line-error test"]
length: 0__proto__: Array(0)
builder.coffee:163 latexmk : ["latexmk -synctex=1 -interaction=nonstopmode -file-line-error -pdf test"]
length: 0__proto__: Array(0)
Okay, we are getting somewhere now. In the dev console - what is the output these? Are any false?
atom_latex.latex.builder.latexmk_toolchain()
atom_latex.latex.builder.binCheck('perl')
atom_latex.latex.builder.binCheck('latexmk')
# Finally set things back to `auto` and run
atom_latex.latex.builder.setCmds()
atom_latex.latex.builder.cmds
The outputs are all false, except for the last one: atom_latex.latex.builder.binCheck('latexmk')
The output to the last two commands are:
atom_latex.latex.builder.setCmds()
builder.coffee:194 Uncaught TypeError: Cannot read property '0' of undefined
at Builder.module.exports.Builder.custom_toolchain (builder.coffee:194)
at Builder.module.exports.Builder.setCmds (builder.coffee:159)
at <anonymous>:1:26
module.exports.Builder.custom_toolchain @ builder.coffee:191
module.exports.Builder.setCmds @ builder.coffee:158
(anonymous) @ VM992:1
atom_latex.latex.builder.cmds
[]
Right - so that is the issue, when setting the custom toolchain, it fails to find perl
, so it believes even latexmk
will fail.,
So in auto
mode the custom toolcahin takes priority.
What you can do is remove all the debug logging, and then remove the perl
check in https://github.com/ashthespy/Atom-LaTeX/blob/b8f3c80f71c2a2d44a6be917af93d94a96a8d3aa/lib/builder.coffee#L170
i.e
if !@binCheck('latexmk')
It should then use latexmk
in auto as intended.
latexmk -xelatex .... and you are fine :-)
see latexmk --help for details
@ashthespy: Tried what you suggested. Now when I use auto
, latexmk
is indeed used. However, if I add something that only works with xelatex
, (e.g., I added \usepackage{fontspec}
, the software tried to use latexmk
, failed, but then stopped and didn't fall back to custom
.
@op183: I don't think that is what I want. If I understand it correctly, your suggestion will always tell atom to use xelatex
, which was precisely why I opened this issue in the first place. I want -- if at all possible -- for it to first try latexmk
, but then automatically fall back to auto
(which I have set to run xelatex
) when it fails. Or am I misunderstanding/missing something?
No as I mentioned in https://github.com/ashthespy/Atom-LaTeX/issues/292#issuecomment-1083069015= this isn't the inbuilt to the package. The fall back is more to check if latexmk
can run on your machine.
For your usecase I would suggest using a .latexcfg
or some other LaTeX build automation tool. You then would need to set this build tool as your custom toolchain. I personally use arara, but there are probably other options.
@iwan1510 I suggest always using auto (latexmk) and in settings define the parameters
For example i use -synctex=1 -interaction=nonstopmode -file-line-error -pdflua to compile my LuaLaTex source. It tells latexmk tu use lualatx and generate pdf.
Other examples
-pdfxe - generate pdf by xelatex -pdfxelatex=program - set program used for xelatex. (replace 'program' by the program name)
and so on ....
If you need even something more flexible see -e code - Execute specified Perl code (as part of latexmk start-up code)
see https://mg.readthedocs.io/latexmk.html for further details
But that would mean you need to switch parameters for each project..
@ashthespy or put all the necessary logic into perl script ... latexmk is nothing but such a perl script https://mirror.szerverem.hu/ctan/support/latexmk/latexmk.pdf
Indeed, you could always implement logic yourself ;)
Ideally, the package should understand the % !TEX program
sequence -- https://github.com/ashthespy/Atom-LaTeX/issues/155
Personally, I just define in each root file what the processor should be
% arara: xelatex: {synctex: yes, shell: yes, options: ['-file-line-error'], interaction: nonstopmode}
And then set my custom tool chain to arara %DOC -v
All different ways to achieve the same thing ;-)
@ashthespy and @op183, thank you for the suggestions and explanations. I think for the time being I have a clear(er) understanding of the current capabilities and limitations of the package with regard to switching TeX engine. I think my original question has been answered. I thank you both and I will close the issue.
This is more of a question rather than a bug report: I mainly use PDFLatex, but sometimes I do use Xelatex. I modify the custom toolchain such that it runs xelatex instead of pdflatex. I can compile a document using xelatex when I choose custom toolchain. The way I understand it, though, if I choose "Auto" toolchain, it would first try latexmk toolchain (and thus using pdflatex, instead of xelatex). If it fails, then the custom toolchain will be used. However, everytime I choose Auto, it will instead runs xelatex instead of pdflatex. If I want to use pdflatex, I had to specifically choose the latexmk toolchain.
I am very new with atom-latex, so I might be missing the obvious here. But am I doing something wrong, or is my understanding about Auto trying latexmk toolchain first before using custom toolchain wrong? Or is there something else going on here?
If it helps, I am trying to compile a very simple file containing just a few lines of text (I am just trying to get a feel for atom-latex here).