Skip to content

Commit

Permalink
BUG: Added filetype extension for beamer .tex files
Browse files Browse the repository at this point in the history
  • Loading branch information
mcocdawc committed Feb 7, 2018
1 parent e6e69fa commit 788796b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion grammars/latex beamer.cson
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fileTypes: []
fileTypes: [
"tex"
]
firstLineMatch: "^\\\\documentclass(\\[.*\\])?\\{beamer\\}"
name: "LaTeX Beamer"
patterns: [
Expand Down

5 comments on commit 788796b

@Tobii42
Copy link

@Tobii42 Tobii42 commented on 788796b Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

since 0.8.5 I have the problem that atom-latex sets the scope to "text.tex.latex.beamer" even in non-beamer LaTeX documents. I had to add the beamer-scope to the spell-checker and "LaTeX-Tree" does no longer work. Small things, nevertheless, I ask myself if this can be related to this change?

Greetings and thanks for your work!

@ashthespy
Copy link
Owner

@ashthespy ashthespy commented on 788796b Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobii42 I noticed this as well - the default grammar is now set to text.tex.latex.beamer for any .tex document.
@mcocdawc what was the reason this was added here?

@mcocdawc
Copy link
Contributor Author

@mcocdawc mcocdawc commented on 788796b Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before going into the code:
My assumption for this change was that regular Tex as well as beamer Tex documents have .tex as file ending. And looking into the code of latex beamer.cson and latex.cson I thought this was the assumption of the original author.

Based on the two REGEXes

# Matches beamer documents
firstLineMatch: "^\\\\documentclass(\\[.*\\])?\\{beamer\\}"
# Matches every documentclass statement, except for beamer ones
firstLineMatch: "^\\\\documentclass(?!.*\\{beamer\\})"

TEX documents are then filtered to be either regular or beamer tex files.
Without

fileTypes: [
  "tex"
]

The test for detecting beamer documents is never performed. So I added it in the PR.

Now the problem is, that usually one has comments in front of the documentclass, e.g. %!TEX TS-program = pdflatex. So both REGEXes don't match and it has to fallback to the default (which apparently now is beamer.)
Tests to confirm this:

  1. The grammar detection works, if there are no comments before \documentclass.
  2. If you do touch test.tex && atom test.tex the empty file has text.tex.latex.beamer grammar.

IMHO the underlying problem is, that firstLineMatch is called on the first line and not on the first uncommented line. On the other hand regular tex files appear much more frequent than beamer tex files,
so it might make sense to change the default. Of course this will surprise users as well, because a beamer document with comments in front will have regular latex instead of beamer grammar.

If you can confirm the finding it might make sense to create an issue regarding firstLineMatch on the atom dev page.

BTW: Thank you for taking over the work. ;-)

@ashthespy
Copy link
Owner

@ashthespy ashthespy commented on 788796b Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your right, I guess it loads the latex beamer grammar before latex and hence the default is now LaTeX Beamer for a .tex that doesn't have a proper firstLineMatch.

I must admit, I am not to well versed with this, but it looks like we can get firstLineMatch to match multiple lines - the underlying function from the grammar-registry is grammarMatchesPrefix

Another option is to load up the base latex grammar, and use an injector for the Beamer class?

@mcocdawc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could read the REGEX and firstLineMatch was self-explaining, but I neither know Javascript nor Coffescript, so I cannot help here.

Please sign in to comment.