When starting a rather long document (book, thesis, etc), almost everyone begins with defining the various chapters, then the various sections and then start a particular section by outlining the points they want to cover in there and then go and fill in the details. That is, they work top down rather than bottom up, by placing each section (or at least every chapter) in a separate file.
But when it comes to math, a common tendency is to type them as is from the beginning to the ending which I believe results is quite a bit of grief as formulas start to get beyond a basic polynomial.
So, when it comes to math I believe a similar approach is necessary.
So, besides the practice of code indenting (ie, having the top down hierarchy easily visible), I have gotten into the habit of closing anything I begin at the same time as opening it. So, with \frac
I immediately go and add {}{}
and then go back and fill in what goes inside. Same with left( right)
and then go back and fill in what is inside. If the fraction happened to be rather complicated I start with:
\frac{}
{}
or for even more complicated ones that I know will take up many lines:
\frac{
}
{
}
Similarly for any environments I do
\begin{}
\end{}
and then go and fill in what is in between.
Finding the appropriate missing brace can sometime be rather difficult and this practice alone has cut down the amount of errors I make significantly. However if I still have an error and can't easily spot it due to the indentation I double click on the opening (or closing brace) and see where the matching one is. This should work with most IDEs - I know it does with TeXShop and TeXWorks.
A difficulty in using this matching technique comes when one has \left( \right.
as the IDEs can not find the matching component and things go awry. So in this case you could either temporarily change the end parenthesis to right)
and remember to go back and fix it, or use a macro that builds this construct so that the IDE only has a {}
to deal with. For example below I use \BracRLeft{}
and \BracRRight{}
to obtain:
The IDE only had to deal with matching brace groups in the actual code.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\@Brac}[3]{\left#1 #2 \right#3}% General \left \right construct
% #1 = bracket type on left
% #2 = argument in brackets
% #3 = bracket type on right
%
\newcommand{\BracR}[1]{\@Brac{(}{#1}{)}}% \left( \right)
\newcommand{\BracRLeft}[1]{\@Brac{(}{#1}{.}}% \left( \right.
\newcommand{\BracRRight}[1]{\@Brac{.}{#1}{)}}% \left. \right)
\makeatother
\begin{document}
\begin{align*}
f(x) &= \BracRLeft{\frac{1}{2}} \\
&\quad -\BracRRight{\frac{3}{4}}
\end{align*}
\end{document}
check-parens
script from my answer as "compiler": it outputs line:pos numbers of mismatching parentheses that I can then directly jump to.\right}
is wrong is it a typo here or also in your code?ln
but a log-like function. If the function you need is not already defined in LaTeX, you can define it with\mathop
. BTW, I use TeXworks and it shows me matching()
's and similar symbols (almost always).vim
, you may rest your text cursor on any delimiter (brace, parenthesis, square bracket) and pressing the%
key,vim
will move to text cursor to the corresponding matching delimiter.