I want to learn debugging of long LaTeX equations like below:

$\tau=\int\frac{dt}{\gamma} = \int\sqrt{1-\frac{v(t)^2}{c^2}}dt = \int\sqrt{1-\frac{1}{c^2}\left(\left(\frac{dx}{dt}\right)^2+\left(\frac{dy}{dt}\right)^2+\left(\frac{dz}{dt}\right)^2 \right) dt$

I have tried to find LaTeX -debugger in places such as iPad's MathBot but MathJax is pretty much the best tool as you can see below and particularly this script here but the tool is only for ready outputs, I press it and it will display in red if something wrong. I would be very happy if I found some tool that put my equation to red in points where I may have error, does such debugging TeX -tool exist?

enter image description here

Perhaps useful to readers

  1. Help me to write Long LaTeX equations fast with colours and possibly with other aids

  2. How to best debug LaTeX?

  • ...I feel I am formulating this question wrong, something about debuggers here, investigating.
    – hhh
    Commented Oct 4, 2012 at 22:17

3 Answers 3


Similar to what I wrote in Help me to write Long LaTeX equations fast with colours and possibly with other aids, and what others have wrote here, the only way to debug these really is to break them down and re write them in a clearer manner.

I don't think there is going to be one generic method that will work for all types of problem. But for this specific case, the equation as is yields the following message:

Missing } inserted.

This particular error usually means that the curly braces are not matched. So the next thing I do is to use a feature that I think is available in most LaTeX Editors/IDEs (I know it is in TeXShop and TeXworks), and click on the opening curly brace to get to locate the matching closing curly brace.

enter image description here

So, the first one matches, and so do the next few:

enter image description here

enter image description here

Once you get to the \sqrt after the third equal sign, you find that there is no matching closing brace:

enter image description here

So that tells you where the problem is. Adding the closing brace fixes the syntax, and you are done with the debugging:

enter image description here

So, all that is now left are the cosmetic aspects. The integral sign seems rather small. So you can either load the bigints package as per Big integral sign, but I found the results better with \mathlarger.

enter image description here


  • I thought that this equation should be in display mode, but resulted in the large square root being too vertical, which did not look good to me, so left it in inline mode
  • Also, not sure why you have braces around the (t), but I left them as is.

Then, adding some new lines and spacing the code to make it more readable we have:



  = \intL\frac{dt}{\gamma} 
  = \intL\sqrt{1-\frac{v(t)^2}{c^2}}dt 
  = \intL\sqrt{
                1 - \frac{1}{c^2} 
                       + \left(\frac{dy}{dt}\right)^2
                       + \left(\frac{dz}{dt}\right)^2 
              } dt$

If you are typing these types of equations often, you might want to consider defining macro such as the \D{} below to make your code even more readable and easier to debug. Furthermore, the d in dt should be upright. So with those changes you get:

enter image description here



  = \intL\frac{\dd{t}}{\gamma} 
  = \intL\sqrt{1-\frac{v(t)^2}{c^2}}\dd{t} 
  = \intL\sqrt{
                1 - \frac{1}{c^2} 
                \left( \D{x}^2 + \D{y}^2 + \D{z}^2 \right)
              } \dd{t}$
  • Don't use \mathlarger for that integral: they are small because you're using inline math mode, while such a formula should always be displayed.
    – egreg
    Commented Oct 5, 2012 at 6:55
  • @egreg: Even with display math the integral sings are quite small. The reason I did not put the final image in display math is because of how the second radical sign is displayed. This is something I have not seen before. Commented Oct 5, 2012 at 6:59

Your forgot to close the square root command \sqrt.

You mean

$\tau=\int\frac{dt}{\gamma} = \int\sqrt{1-\frac{v(t)^2}{c^2}}dt = \int\sqrt{1-\frac{1}{c^2}}\left(\left(\frac{dx}{dt}\right)^2+\left(\frac{dy}{dt}\right)^2+\left(\frac{dz}{dt}\right)^2 \right) dt$

I guess.

  • ...I know the solution, I want some tool that I press and it shows some colors perhaps statistic analysis or something to look for possible -error-spots. This kind of errors like missing last parethesis may require many minutes work to find out by investigating each spot separately.
    – hhh
    Commented Oct 4, 2012 at 20:45
  • @hhh TeX's error message ! Missing } inserted. <inserted text> } l.25 told you all there is to debug. A proper editor can highlight the erroneous line and/or jump to it when you click on the error message. Commented Oct 4, 2012 at 20:48
  • @Qrrbrbirlbel TeX's error message, how did you get it? PdfLatex sounds overkill here -- I usually debug TeX with pdflatex but it require all kind of headers/unnecessary things -- sorry stupid question but I am serious. How do you get this error -msg and highlighting i.e. how do you debug?
    – hhh
    Commented Oct 4, 2012 at 20:54
  • It's in the .log file. How did you now in the first place that you had an error? Commented Oct 4, 2012 at 21:06
  • 1
    @hhh Well, that would have been helpful to know in the first place, that you don't use your local TeX distribution. Try for example an Online LaTeX Equation Editor. Here you can see your results live. The one linked tells you “You have more open '{' brackets than closed '}' brackets”. Commented Oct 4, 2012 at 22:45

I don't know if there is a tool that will do exactly what you desire. Perhaps it is not even possible to have such a tool for the general case (LaTeX being a macro language etc). Having a decent editor with a good LaTeX plugin is a good step in this direction though (colors, highlighting closing braces etc).

Apart from that, it is also helpful to use multiple lines instead of a single long one. Indentation too. This way, you can always comment out a single line at a time. This always helps in pinpointing the error. Look how much more readable your code can be.

\tau = \int\frac{dt}{\gamma} 
     = \int\sqrt{1-\frac{v(t)^2}{c^2}}dt 
     = \int\sqrt{1-\frac{1}{c^2}}
           \left(\left(\frac{dx}{dt}\right)^2 + 
                 \left(\frac{dy}{dt}\right)^2 +
           \right) dt

Another technique that I find useful is working in chunks, or more accurately writing the command first and filling the arguments later. E.g.

% first step

% second step

Defining custom commands also can be very helpful. E.g.


Another approach would be to check if there is a decent converter from Word or LibreOffice equations to LaTeX and using it, but this is something that may be rather limiting in the long run since you will probably need to hand tweak the equations (no custom commands etc)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .