LaTeX Syntax Checker?

Casey Pelous

Senior Discount
VVO Supporter 🍦🎈👾❤
Joined
Sep 24, 2018
Messages
732
Location
USA, upper left corner
SL Rez
2007
Joined SLU
February, 2011
SLU Posts
10461
I'm working on a document in a typesetting program called LaTeX. Very nifty program, very powerful, makes beautiful typesetting (if you're a sucker for that stuff like I am.) It blows Word's typesetting engine off the page and out the door.

It's really a scripting language, and somewhere in this document is one of those nightmare errors that fools the internal (TexStudio) syntax checker into thinking something is wrong with a couple of my tables when the error is really somewhere upstream. How I know this: I can take the alleged error-riddled code into a blank document and it renders just fine and dandy. In fact, by going back and forth from main doc to "test doc", I've narrowed down the problem area to about 1,000 lines of text. :eyepop:

Before I spend the rest of Saturday either fine-tooth-combing 1,000 lines of code or drowning myself in vodka, does anyone have a line on a better LaTeX syntax checker than the one built into TexStudio? Or have a clever scheme for finding this/these error/errors that are tripping the "Extra alignment tab has been changed to \cr" fatal error? I have tried running a LaTeX package designed for vim, but don't seem to be getting any sort of results with that at all. (I may be doing it wrong -- there's a vim-easy and a vim-difficult that seems to be some sort of command line contraption, and I'll bet that's the good one.)

For those familiar with programming/scripting but unfamiliar with LaTeX, that gibberish is telling me I have too many or too few columns for the data I want to put into a table. I definitely do not, so something upstream is showing up as an extra &, or $, or \\, or .... some damn thing. Or I have an extra or unclosed curly brace somewhere. Or this document is possessed by hellspawn -- not a possibility I've completely written off just yet.
 

Grandma Bates

Only mostly banned....
VVO Supporter 🍦🎈👾❤
Joined
Sep 20, 2018
Messages
251
Location
Airport
Joined SLU
Yes
SLU Posts
-1000
I use emacs which is pretty good about parsing latex. It has a bit of steep learning curve, but once you get used to it, it only hurts a little. Unfortunately, there may not be a magic bullet, and you just have to tough it out and perform a bisection. Remove half the code see what happens, and then if it is okay it is in the other half. Then take the other half, and break it into two. Repeat until you run out of hair to pull.

In terms of finding errors, I generally try to start in the middle half and work outwards. So remove things from the innermost environment and start working out until you find the code causing problems. One of the frustrating things about latex is that some environments require something inside them and will throw errors if they are empty. (For example, sometimes "\item" by itself will be an error, and you have to replace it with "\item ~" so it knows there is white space. The hard part is reading the cryptic error messages and trying to figure out if something is missing or something extra is in place. (Extra alignment characters are frustrating too.)

If the command being defined is very long you should be able to put in line breaks to make it look better. If it is inside a regular @ environment then that may not be the case. If you put an "%" at the end of a line without anything after it, that usually allows it compile. Sometimes, though, the best option is to hunt down and publicly humiliate the person who typed up something that badly constructed. Just be warned, what comes around.....
 
Last edited:
  • 1Like
  • 1Thanks
Reactions: Casey Pelous and Khamon

Casey Pelous

Senior Discount
VVO Supporter 🍦🎈👾❤
Joined
Sep 24, 2018
Messages
732
Location
USA, upper left corner
SL Rez
2007
Joined SLU
February, 2011
SLU Posts
10461
Do this help? No?
I knew as soon as I brought up LaTeX in this place ............. :p

I use emacs which is pretty good about parsing latex. It has a bit of steep learning curve, but once you get used to it, it only hurts a little. Unfortunately, there may not be a magic bullet, and you just have to tough it out and perform a bisection. Remove half the code see what happens, and then if it is okay it is in the other half. Then take the other half, and break it into two. Repeat until you run out of hair to pull.

[\QUOTE]

Thanks, Grandma!

Yep, that's how I spent the afternoon yesterday. I've got it isolated to one little bastard of a \multicolumn command -- if I comment it out, everything works fine. It's not like it's a complex line of code -- I'm 99.999% sure I have it coded correctly, unless I've developed a truly hideous case of confirmation bias. I mean, sheesh, it's only three simple parameters. The xtabular that command is in compiles just fine -- but the next table throws that error until I comment out that line.

Further weirdness --- I can reproduce all this by copying the three tables to a new document (with the same preamble.) Table 1 is the one with the monkey-wrench code line. 2 and 3 are the ones that throw errors. Stack 'em 1, 2, 3, and boom, errors. Stack 'em 2, 3, 1 and everything's hunky dory.

Truth is, everything comes out fine with that line commented out -- it controls a line (\tabletail} that only gets printed if the table is split across pages, and the table is not splitting. However, I really want to understand WTF is going on!

Aside from this little misadventure, it has been really fun to learn this thing -- I haven't really scripted much of anything since my SL days.
 

Katheryne Helendale

🐱 Kitty Queen 🐱
Joined
Sep 20, 2018
Messages
5,369
Location
Right... Behind... You...
SL Rez
2008
Joined SLU
October 2009
SLU Posts
65535
Thanks, Grandma!

Yep, that's how I spent the afternoon yesterday. I've got it isolated to one little bastard of a \multicolumn command -- if I comment it out, everything works fine. It's not like it's a complex line of code -- I'm 99.999% sure I have it coded correctly, unless I've developed a truly hideous case of confirmation bias. I mean, sheesh, it's only three simple parameters. The xtabular that command is in compiles just fine -- but the next table throws that error until I comment out that line.

Further weirdness --- I can reproduce all this by copying the three tables to a new document (with the same preamble.) Table 1 is the one with the monkey-wrench code line. 2 and 3 are the ones that throw errors. Stack 'em 1, 2, 3, and boom, errors. Stack 'em 2, 3, 1 and everything's hunky dory.

Truth is, everything comes out fine with that line commented out -- it controls a line (\tabletail} that only gets printed if the table is split across pages, and the table is not splitting. However, I really want to understand WTF is going on!

Aside from this little misadventure, it has been really fun to learn this thing -- I haven't really scripted much of anything since my SL days.
I know next to nothing about LaTeX, so I could be wildly off base. But it sounds to me like you've got a gotcha statement in the other tables that, by themselves don't break anything, but if that one command in the first table gets executed, it causes the gotcha statements to throw errors. I hope I'm making sense.
 
  • 1Like
Reactions: Grandma Bates

CronoCloud Creeggan

Redheaded
VVO Supporter 🍦🎈👾❤
Joined
Sep 26, 2018
Messages
581
Location
Central Illinois
SL Rez
2006
Joined SLU
07-25-2012
SLU Posts
278
Which OS? If you're on Linux feed the .tex file into pdflatex directly in the terminal.

pdflatex filename.tex

That might give you more informative error messages.
Also take a look at this: Tables longer than a single page
 
  • 1Agree
Reactions: Grandma Bates

Argent Stonecutter

Emergency Mustelid Hologram
Joined
Sep 20, 2018
Messages
2,701
Location
Coonspiracy Central, Noonkkot
SL Rez
2005
Joined SLU
Sep 2009
SLU Posts
20780
Things have improved, I see. The last time I tried using TeX I got half a dozen pages full of close parentheses with an obscure error message in the middle.

Makes nice documents, I admit.
 

Bartholomew Gallacher

Well-known member
Joined
Sep 26, 2018
Messages
2,999
SL Rez
2002
TeX was published in 1978 by the godfather of programming, Donald E. Knuth. LaTeX was released in 1984 by Leslie Lamport and is basically a collection of macros to make TeX more usable and accessible. LaTeX just means something like "Lamport TeX." Since then most people don't use TeX alone and do prefer LaTeX.

LaTeX is very popular in natural sciences, mostly mathematics, physics and computer sciences as well due to its superior typesetting of all kind of formulas. Most thesis papers there are being written in LaTeX, journals as well. It also inspired HTML a lot.

I once upon a time typed the physics diploma thesis for a friend in LaTeX, who was not so well versed using it, and earned some money. The output was quite nice, the way until then sometimes... its own adventure with over 400+ formulas.

LaTeX is by no means WYSIWYG. There are though graphical frontends for it, like LyX. Almost every better text editor on Unix features a LaTeX mode.

Maybe ChkTeX is what Casey is looking for. It describes itself as lint for LaTeX.
 
Last edited:

Argent Stonecutter

Emergency Mustelid Hologram
Joined
Sep 20, 2018
Messages
2,701
Location
Coonspiracy Central, Noonkkot
SL Rez
2005
Joined SLU
Sep 2009
SLU Posts
20780
This would have been about 1980. I had a choice of TeX or troff, and ended up going with troff.

Later on I got rather excited about SGML, which was another dead end.
 

Casey Pelous

Senior Discount
VVO Supporter 🍦🎈👾❤
Joined
Sep 24, 2018
Messages
732
Location
USA, upper left corner
SL Rez
2007
Joined SLU
February, 2011
SLU Posts
10461
Victory! :cheer:

There was a clue buried in that link you gave me, CronoCloud Creeggan, so thank you so much for that. I will definitely check out ChkTeX, too, Bartholomew Gallacher. Thanks.

Of course, the problem is always obvious after you've solved it. Katheryne Helendale was pretty much on the track of the problem. Turns out I had left out or left blank one or two of the table parameters I thought were optional.

Funny thing is, the first table with missing parameters will compile just fine -- but something about the missing parameter(s) blows up the next table, making it throw error messages that may be technically true but are completely useless for finding the problem. Which explains why I saw a couple of examples where people got away with it in single table examples.

Now, don't y'all think the compiler should know I've been working on this for more than two days and do something more demonstrative than the deadpan, "Process exited normally." I mean, geeze, how about some heavy breathing or fireworks?
 

CronoCloud Creeggan

Redheaded
VVO Supporter 🍦🎈👾❤
Joined
Sep 26, 2018
Messages
581
Location
Central Illinois
SL Rez
2006
Joined SLU
07-25-2012
SLU Posts
278
Code:
\documentclass[letterpaper,english]{letter}
\usepackage[letterpaper,left=1in,top=0.5in,right=1in,bottom=0.5in,nohead,nofoot]{geometry}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Times New Roman}
\usepackage[latin9]{inputenc}
\makeatletter
\usepackage{babel}
\usepackage{graphicx}
\makeatother
\begin{document}
\address{Ms. CC Creeggan \\ Second Life}
\begin{letter}
YAY! \\
Glad you got it figured out.\\
\end{letter}
\end{document}
 
  • 1Thanks
Reactions: Casey Pelous

Grandma Bates

Only mostly banned....
VVO Supporter 🍦🎈👾❤
Joined
Sep 20, 2018
Messages
251
Location
Airport
Joined SLU
Yes
SLU Posts
-1000
Victory! :cheer:

There was a clue buried in that link you gave me, CronoCloud Creeggan, so thank you so much for that. I will definitely check out ChkTeX, too, Bartholomew Gallacher. Thanks.

Of course, the problem is always obvious after you've solved it. Katheryne Helendale was pretty much on the track of the problem. Turns out I had left out or left blank one or two of the table parameters I thought were optional.

Funny thing is, the first table with missing parameters will compile just fine -- but something about the missing parameter(s) blows up the next table, making it throw error messages that may be technically true but are completely useless for finding the problem. Which explains why I saw a couple of examples where people got away with it in single table examples.

Now, don't y'all think the compiler should know I've been working on this for more than two days and do something more demonstrative than the deadpan, "Process exited normally." I mean, geeze, how about some heavy breathing or fireworks?
With latex there are no missing parameters. The compiler just pulls in the next set of tokens as necessary. If you have a token that is more than one character then you can specify tokens using braces, ex: {your token is in here}. If you left off the braces latex just took the next tokens which were likely treated as single characters. If one of those tokens was used in a following command they likely got lost or pulled apart. When they were expanded in the macro or the remaining text was processed it probably threw the error. This may be why the order mattered.

ETA: This is why you get different results between $x^12$ and $x^{12}$. In the first the exponent is 1 and in the second the exponent is 12. The token that is the argument to the ^ operator is the exponent, so for more than one character you need braces.