TeXblog

 Typography with TeX and LaTeX

Archive for the 'Mathematics' Category

Springer recommends eqnarray

April 6th, 2012 by Stefan Kottwitz

I just read on LaTeX-Community.org, that the publisher Springer still recommends to use eqnarray. I could not believe that, so I went to Book Manuscript Guidelines, choose Manuscript Preparation in LaTeX and downloaded svmult.zip, which contains the Springer class for contributed books, proceedings, and similar. It has a folder called templates, which contains a file author.tex. In this file I could read:

...
% Use this file as a template for your own input.
...
Use the standard \verb|equation| environment to typeset
your equations, e.g.
%
\begin{equation}
a \times b = c\;,
\end{equation}
%
however, for multiline equations we recommend to use the
\verb|eqnarray| environment\footnote{In physics texts
please activate the class option \texttt{vecphys} to depict
your vectors in \textbf{\itshape boldface-italic} type -
as is customary for a wide range of physical subjects}.
\begin{eqnarray}
a \times b = c \nonumber\\
\vec{a} \cdot \vec{b}=\vec{c}
\label{eq:01}
\end{eqnarray}

A close look shows this template doesn’t even align at the relation symbol, which could be done with eqnarray. The example equations are simply right aligned. One could see that in the output if one of those equations would be extended.

eqnarray is considered to be obsolete and faulty, as I wrote 2008 in the comparison eqnarray vs. align. Actually it’s been obsolete since the amsmath package appeared. The better ways are described in its manual, such as using align, gather or multline.

I’m sure most experienced LaTeX users know that fact, and LaTeX beginners are told this frequently in forums and Usenet groups. Why it does not reach Springer? Perhaps this publisher doesn’t really welcome LaTeX for scientific publishing and doesn’t care if his templates are outdated. I wonder what they use then.

Category: Mathematics | 4 Comments »

Closed root symbols

Oktober 2nd, 2011 by Stefan Kottwitz

handwritten closed square root
In LaTeX/Mathematics, Wikipedia writes:

Some people prefer writing the square root “closing” it over its content. This method arguably makes it more clear just what is in the scope of the root sign.

It shows a solution defining \sqrt in terms of the default one, which works well. However, Wikipedia continues:

Unfortunately this code won’t work if you want to use multiple roots: if you try to write \sqrt[b]{a} … you’ll just get a wrong output. In other words, you can redefine the square root this way only if you are not going to use multiple roots in the whole document.

handwritten roots
On TeX.SX Matthias posted the question, how to solve this for roots of arbitrary degree. I had a look into latex.ltx and decided to redefine the internet \r@@t macro, still similar to the Wikipedia solution:

\makeatletter
\let\oldr@@t\r@@t
\def\r@@t#1#2{%
\setbox0=\hbox{$\oldr@@t#1{#2\,}$}\dimen0=\ht0
\advance\dimen0-0.2\ht0
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{\box0\lower0.4pt\box2}}
\LetLtxMacro{\oldsqrt}{\sqrt}
\renewcommand*{\sqrt}[2][]{\oldsqrt[#1]{#2}}
\makeatother

Now we get a closed root symbol for example also for cubic roots. However, roots without optional arguments, i.e. are not closed. Finally, this can be fixed by forcing \sqrt using the optional argument, if necessary just using a space because. An empty optional argument would cause wrong spacing.

\usepackage{letltxmacro}
\LetLtxMacro{\oldsqrt}{\sqrt}
\renewcommand*{\sqrt}[2][\ ]{\oldsqrt[#1]{#2}}

Here we did not use TeX’s \let command, but the letltxmacro package which works safer for LaTeX macros with optional arguments. See complete source example. Output:

Rlosed roots

Matthias wrote a suggestion for incorporating the solution on the Wikipedia discussion page.

This was originally discussed on TeX.SX: “Closed” (square) root symbol.

Category: TeX.SX, Fonts and Symbols, Mathematics | No Comments »

Inline math: $…$ vs. \(…\)

April 3rd, 2009 by Stefan Kottwitz

l2tabu, a text informing about obsolete packages and commands, recommends to replace $$…$$ by \[…\], but it doesn’t say a word about the difference between $…$ and \(…\). “Mathmode” by H. Voss does tell something, but it says in v2.40: “In general $…$ is the best choice”. I doubt it, and when I mentioned here some thoughts about that, the author noticed it without much comment. Because of a question on Matheboard today I’ve listed some reasons why I’m preferring the \(…\) environment:

  • With \(…\) you can easily distinguish opening and closing of the math mode, in contrary to $…$, mistakes in code could be harder to find with $.
  • LaTeX does additional error checks in \(…\), whereas $…$ is plain TeX and is used internally by \(…\).
  • \(…\) is working inside alltt-environments, $…$ is causing errors.
  • Both \( and \) could be redefined or extended easily.
  • Though \( and \) are not robust, possibly causing problems in sectioning for instance, that could be fixed by just loading the fixltx2e package.

In general I recommend to use LaTeX macros instead of corresponding plain TeX commands.

Category: LaTeX General, Mathematics | No Comments »

Tutorial: Commutative Diagrams using TikZ

Februar 4th, 2009 by Stefan Kottwitz

In previous posts I’ve shown some examples how the TikZ graphics package could be used to draw mathematical diagrams like exact sequences and commutative diagrams. Felix Lenders has written a tutorial called Commutative Diagrams using TikZ dealing with this subject and has published it today. In that paper he’s describing basic syntax, styles, arrows, curves, positioning issues and more. The tutorial contains several examples with the corresponding source code.

To read related blog posts have a look at the TikZ category.

Category: News, pgf/TikZ, Mathematics | 6 Comments »

LaTeX-Award on Matheplanet.com

Januar 26th, 2009 by Stefan Kottwitz

The big german math portal Matheplanet.com has presented its 7th annual awards yesterday evening, Jan 25th. Those awards honor the efforts of community members who are providing help, knowledge, work and time to all of the Matheplanet users. More than 4000 votes were given in different categories like mathematics, physics, computer science, moderation, information, article writing, book reviewing and more. Because that math site has a lively LaTeX forum there’s also an award for honoring the best LaTeX advisor. This year (and the last year too) the voters have chosen me, and I’m very proud of it, because I’m part of the Matheplanet community for many years and I appreciate this site and its members. At this place I want to say thank you for your feedback.
If you’re having LaTeX questions, especially if they are concerning mathematics, you’re invited to visit the Matheplanet LaTeX forum to post questions and also to help other users. If you’re interested in LaTeX or just look for advice you may also visit our LaTeX User Group.

Category: News, Events, LaTeX General, Mathematics | 3 Comments »

Math formulas and arrows with TikZ

Januar 19th, 2009 by Stefan Kottwitz

In the Art of Problem Solving Forum somebody asked for help in creating a construction for proofs and demonstrations in Logic by LaTeX commands. Math expressions should be aligned, some connected by arrows going vertically and horizontally.
Regarding arrows I would use tikz and also its matrix library for math nodes. The nodes could be connected by -| or |- path construction operations, like

\draw (node1) -| (node2) |- (node3);

For creation of the example given in the thread on AoPS I’ve used a matrix of math nodes, some empty nodes for alignment and |- -| arrows, here’s the compilable example code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[every node/.style={anchor=west}]
  \matrix (m) [matrix of math nodes,
    nodes in empty cells]{
    \quad & 1.\quad (x)(Q\supset Fx) & \\
    & 2.\quad Q\supset Fx & \textrm{I,\textbf{UI}} & \\
    & 3.\quad Q \\
    & 4.\quad Fx & 2, 3, \textrm{ M.P.}\\
    & 5.\quad (x)Fx & 4, \textrm{ \textbf{UG}} \\
    & 6.\quad Q\supset(x)Fx & 3-5, \textrm{ C.P.} \\
    & 7.\quad \parbox[t]{2.9cm}{%
             $(x)(Q\supset(x)Fx)\supset$\\
             $[Q\supset(x)Fx]$} & 1-6, \textrm{ C.P.}\\};
  \draw[-stealth] (m-7-2.north east)
               -| (m-1-1.west) |- (m-1-2);
  \draw[-stealth] (m-6-2.north east)
               -| (m-3-1.east) |- (m-3-2);
\end{tikzpicture}
\end{document}

Output:

logic diagram with TikZ

Category: pgf/TikZ, Mathematics | 1 Comment »

TikZ: Commutative diagrams with crossing edges

Januar 7th, 2009 by Stefan Kottwitz

When one edge of a graph passes over or under another edge there may be a small gap needed in the drawing of one of those edges. An easy trick is to draw the upper edge two times: first with the background color and more thickness, afterwards normally, like
<node1> edge [-,line width=6pt,draw=white] <node2> edge <node2>
Here’s an example diagram used in the definition of the pull-back of a Banach bundle:

Tikz commutative diagram

The source code:

\begin{tikzpicture}
  \matrix (m) [matrix of math nodes, row sep=3em,
    column sep=3em]{
    & f^\ast E_V& & \vphantom{f^\ast}E_V \\
    f^\ast E & & \vphantom{f^\ast}E & \\
    & U & & V \\
    M & & N & \\};
  \path[-stealth]
    (m-1-2) edge (m-1-4) edge (m-2-1)
            edge [densely dotted] (m-3-2)
    (m-1-4) edge (m-3-4) edge (m-2-3)
    (m-2-1) edge [-,line width=6pt,draw=white] (m-2-3)
            edge (m-2-3) edge (m-4-1)
    (m-3-2) edge [densely dotted] (m-3-4)
            edge [densely dotted] (m-4-1)
    (m-4-1) edge (m-4-3)
    (m-3-4) edge (m-4-3)
    (m-2-3) edge [-,line width=6pt,draw=white] (m-4-3)
            edge (m-4-3);
\end{tikzpicture}

This topic was discussed on Matheplanet.com.

If you want to read more about commutative diagrams with TikZ have a look here: Chains with labeled edges.

Category: pgf/TikZ, Mathematics | 5 Comments »

TikZ: chains with labeled edges

Oktober 19th, 2008 by Stefan Kottwitz

These days I wanted to include some commutative diagrams in a math text. There are already packages designed for this purpose, like amscd and xy-pic. I’ve used xy-pic before and didn’t like its usability and output much. The most recent documents I found on CTAN were dated 1999, many links on its homepage were dead, though xy-pic still works fine today, also with pdflatex. But I decided to use pgf/TikZ now because it can be used to create graphics in many different ways. For instance the beamer class is using pgf already, so why not use it also for math diagrams.

For writing exact sequences the chains library seemed very useful, but I missed the feature to label the edges of a chain. Just arrows weren’t enough, I needed to write maps over, under or just next to it.

I decided to make a workaround by modifying the join method of the chain library. Its syntax is join=with<node> by <options>, I’m changing the syntax to join={node[options] {label}}, this is the code to achieve the effect wanted:

\tikzset{join/.code=\tikzset{after node path={%
\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
edge[every join]#1(\tikzchaincurrent)\fi}}}

Some general settings before starting the diagrams:

\tikzset{>=stealth',every on chain/.append style={join},
         every join/.style={->}}

Now a short exact sequence can be written for example:

\begin{tikzpicture}[start chain] {
    \node[on chain] {$0$};
    \node[on chain] {$A$} ;
    \node[on chain, join={node[above]
          {$\scriptstyle\varphi$}}] {$B$};
    \node[on chain, join={node[above]
          {$\scriptstyle\psi$}}] {$C$};
    \node[on chain] {$0$}; }
\end{tikzpicture}

Output:

long exact sequence

For more complex diagrams you could use the matrix library to create matrices of math nodes, connecting the nodes by chains. Here’s the code for the Short 5-Lemma as example:

\begin{tikzpicture}
  \matrix (m) [matrix of math nodes, row sep=3em,
    column sep=3em]
    { 0 & A  & B  & C  & 0 \\
      0 & A' & B' & C' & 0 \\ };
  { [start chain] \chainin (m-1-1);
    \chainin (m-1-2);
    { [start branch=A] \chainin (m-2-2)
        [join={node[right] {$\scriptstyle\eta_1$}}];}
    \chainin (m-1-3) [join={node[above]
                      {$\scriptstyle\varphi$}}];
    { [start branch=B] \chainin (m-2-3)
        [join={node[right] {$\scriptstyle\eta_2$}}];}
    \chainin (m-1-4) [join={node[above]
                      {$\scriptstyle\psi$}}];
    { [start branch=C] \chainin (m-2-4)
        [join={node[right] {$\scriptstyle\eta_3$}}];}
    \chainin (m-1-5); }
  { [start chain] \chainin (m-2-1);
    \chainin (m-2-2);
    \chainin (m-2-3) [join={node[above]
                      {$\scriptstyle\varphi'$}}];
    \chainin (m-2-4) [join={node[above]
                      {$\scriptstyle\psi'$}}];
    \chainin (m-2-5); }
\end{tikzpicture}

Output:

long exact sequence

See full LaTeX source code.
During writing of this entry I’ve applied that modification also on CQF.info.

Category: pgf/TikZ, Mathematics | 13 Comments »

An extension to amsmath matrix environments

September 30th, 2008 by Stefan Kottwitz

Inspired by a question on matheplanet.com and remembering the cases redefinition I’ve shown some days ago I got the idea to extend the internal macro \env@matrix of amsmath.sty. I wanted to use the matrix environments together with array features like alignment, vertical lines, formatting and special commands.
The mathtools package provides something similar by its starred matrix environments that support one optional parameter that will be applied to all matrix columns. The following redefinition will introduce an optional parameter to amsmath array environments that allows column-specific customization:

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

If you put these lines into your document preamble the pmatrix, bmatrix, vmatrix, Bmatrix, Vmatrix etc. environments will accept an optional parameter. If you don’t provide this parameter those environments will work like usual. Here’s one example showing an augmented matrix containing a vertical line:

\[
\begin{pmatrix}[cc|c]
  1 & 2 & 3\\
  4 & 5 & 9
\end{pmatrix}
\]
augmented matrix

Another more complex example just showing some array features like different alignment because of the signs, color change and bold font:

\[
\begin{bmatrix}[*2cr@{\quad}|@{\quad}>{\bf\color{red}}r]
  a & b & 1  &  4 \\
  c & d & -2 & -3
\end{bmatrix}
\]
augmented matrix

Though \bf is an obsolete font command standard classes still support it and I’ve just used it because \boldmath is invalid in math mode, in general I advice against using \bf.

Category: Mathematics | 5 Comments »

amsmath: cases and \arraystretch

September 24th, 2008 by Stefan Kottwitz

The amsmath cases environment is using the array environment internally, like its matrix environments. If you want to change the interline spacing of matrices you could redefine \arraystretch, like for any array environment. But it won’t work for cases - amsmath defines an arraystretch value of 1.2 internally.

A solution is to redefine the \env@cases macro. Here’s a redefinition, introducing an optional parameter controlling the spacing:

\makeatletter
\renewcommand*\env@cases[1][1.2]{%
  \let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{#1}%
  \array{@{}l@{\quad}l@{}}%
}
\makeatother

Now by \begin{cases} … \end{cases} the default value of 1.2 will be used, but by using the optional parameter like \begin{cases}[0.8] … \end{cases} the spacing will be adjusted accordingly.

This topic was discussed on mrunix.de.

Category: Mathematics | 6 Comments »