ashthespy / Atom-LaTeX

The only LaTeX package you need for typesetting with Atom.
https://atom.io/packages/atom-latex
MIT License
22 stars 9 forks source link

Fix file extension matching #211

Closed maxb2 closed 5 years ago

maxb2 commented 5 years ago

Resolves #205.

/\.([^\/]*)$/ matches the first dot and everything after it. This captures more than just the file extension if there are dots in the filename. e.g. file.test.tex -> .test.tex

/\.([^\/.]*)$/ matches the last dot and everything after it by including a dot in the negated set. This will capture just the extension. e.g. file.test.tex -> .tex

ashthespy commented 5 years ago

Hi, matching the last dot was done on purpose (https://github.com/ashthespy/Atom-LaTeX/pull/89#issuecomment-321505504) to handle cases such as file.tex.tikz

That being said, I see that this is dissimilar to how the pdf path is determined (https://github.com/ashthespy/Atom-LaTeX/commit/fcbebee4b56e3e0ba6a83329394636cd28cf2145). There we strip only only the last part. I guess we could make things a bit more robust by checking against the normal expected extensions akin to: https://github.com/ashthespy/Atom-LaTeX/blob/0075d6663cf011f243f166f54205ec285237bdaf/lib/manager.coffee#L46-L50

What do you think?

maxb2 commented 5 years ago

Your version matches the first dot. This could strip out parts of the filename that the user has set. For example, file.1.tex and file.2.tex both compile to file.pdf. This also breaks the bibtex compilation.

As-is, files of the form foo.bar.ext will not compile using the default toolchain.

pdflatex takes the file given (or the root file name with an assumed .tex ending) and produces files with the same name but with the last extension replaced. For example, pdflatex foo.bar.ext -> foo.bar.aux. However, bibtex needs the .aux file generated by pdflatex.

In the current implementation, %DOC=foo and %EXT=.bar.ext. With this stripping %TEX %ARG %DOC will not compile because neither foo nor foo.tex exist. You are required to run %TEX %ARG %DOC%EXT. This produces foo.bar.aux. There is no way to run the bibtex command with %DOC and %EXT.

With the changes in this PR and changing the default toolchain to %TEX %ARG %DOC%EXT && %BIB %DOC && ... this should be able to handle any file extensions provided that the main file is a valid latex document.

ashthespy commented 5 years ago

If my memory serves me right, all the extension stuff was added predominantly for people playing around with non standard extensions such as Knitr, TikZ and other stuff.

Hi, matching the last dot was done on purpose (#89 (comment)) to handle cases such as file.tex.tikz

Give me some time, will implement something that doesn't break this compatibility as well as lets you set your desired foo.bar.tex -> foo.bar.pdf

maxb2 commented 5 years ago

The way you handle file extensions with the default toolchain doesn't work even for nonstandard extensions. I made a folder with only a file called foo.tex.tikz in it. When I try to compile it, I get this error message:

> pdflatex -synctex=1 -interaction=nonstopmode -file-line-error foo

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
! I can't find file `foo'.
<*> foo

(Press Enter to retry, or Control-D to exit)
Please type another input file name
! Emergency stop.
<*> foo

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.

This is because you are throwing away parts of the filename. %TEX %ARG %DOC translates to pdftex -synctex=1 -interaction=nonstopmode -file-line-error foo when it should be pdftex -synctex=1 -interaction=nonstopmode -file-line-error foo.tex.tikz

I could see how it wouldn't error out if there were also a file called foo.tex in the folder. But then the toolchain would be compiling foo.tex and not foo.tex.tikz. This is still unwanted behavior though.

ashthespy commented 5 years ago

Closing in favour of #213 - thanks for the help!