3 April 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 »
4 February 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 |
5 Comments »
26 January 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 »
19 January 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:
Category: pgf/TikZ, Mathematics |
No Comments »
7 January 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:
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 |
3 Comments »
19 October 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:
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:
See full LaTeX source code.
During writing of this entry I’ve applied that modification also on CQF.info.
Category: pgf/TikZ, Mathematics |
11 Comments »
30 September 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}
\]
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}
\]
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 |
2 Comments »
24 September 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 |
2 Comments »
16 September 2008 by Stefan Kottwitz
Today it has been announced that a new paper “Writing scientific documents using LaTeX” by Andrew J. Bennieston has been uploaded to CTAN, an introduction on 13 pages. I took a brief glimpse at this paper.
Nice to have another introduction, but some odd things catched my eye. The author introduces $$…$$ as shortcut form for display math mode without equation numbering, but \[…\] is recommended instead of this, like mentioned in “Obsolete packages and commands“, $$…$$ should be avoided. The author describes also the obsolete math environment eqnarray. Though he is mentioning that the align environment should be preferred he didn’t say why. As one can see in the output of the equations (2), (3) and (4) there’s something wrong with the spacing next to the relation symbol, the author just didn’t use eqnarray correctly, there’s a & separation symbol missing on each line. It’s compilable, but if you extend the right side then the = symbols will not be aligned any more, compare the syntax with this reference. The right sides of those equations including the = symbol are actually centered, not noticeable because they are having equal width.
This article contains also a wrong syntax of the align environment. The demonstration example doesn’t contain any & separation symbol, the alignment is just a coincidence.
I’m referring to the fourth Edition of September 13, 2008, uploaded to CTAN today. I’m expecting that the mistakes will be corrected soon, of course I will send the author an email containing my comments.
Category: LaTeX General, Mathematics |
1 Comment »
7 August 2008 by Stefan Kottwitz
Today Tomek posted very impressive 3D drawings made with pgf/TikZ in the LaTeX Community Forum.
Here’s one of the drawings showing a cylindrical projection:
More examples and their complete sourcecode by Tomasz M. Trzeciak can be found in the corresponding posting in the LaTeX Community Forum.
For even more examples demonstrating the capabilities of pgf/TikZ visit the TikZ example gallery provided by Kjell Magne Fauske.
Category: pgf/TikZ, Mathematics |
2 Comments »