You surely can define your shortcuts; indeed you should.
Let's make some examples. Suppose your document is full of Fourier transforms, for which you need a fancy F. Instead of writing every time
$\mathcal{F}(f)$
it's surely better to define a new command, say
\newcommand{\FT}{\mathcal{F}}
(choose any name you like), so that you can type
$\FT(f)$
and get the same result as before, with a big bonus! If you change your mind about the notation, you can simply modify the definition.
Another example. The "gradient" operator is not predefined; so you might want to have a command for it:
\DeclareMathOperator{\grad}{grad}
A different one; my preferred notation for vectors is, say, \mathbf{v}
. However, since conventions are different, I never type vectors in that way, but prefer to have
\newcommand{\vect}[1]{\mathbf{#1}}
for the same reason as before; I might change my mind and want to modify the appearance, say for using bold italic; this would be accomplished just by saying
\usepackage{bm}
and changing the above into
\newcommand{\vect}[1]{\bm{#1}}
How do you organize this? Here's an example:
\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % input encoding UTF-8
% Useful packages
\usepackage{amsmath,amssymb,amsthm}
% add all the packages you need
% Personal definitions
\newcommand{\FT}{\mathcal{F}} % Fourier transform operator
\DeclareMathOperator{\grad}{grad} % gradient
\newcommand{\vect}[1]{\mathbf{#1}} % vectors and matrices
\begin{document}
...
\end{document}
Add definitions while you find that they are useful for distinguishing logical units of your document.
There are two \newcounter
calls inside the macro \pichart
.
When the macro is called the second time, then the counters are already defined and you get the error messages about already defined commands \c@a
and \c@b
, which are the internal command representation of the counters.
Move the \newcounter
calls outside and reset the counters inside the macro:
\newcounter{a}
\newcounter{b}
\newcommand*{\piechart}[1]{%
\setcounter{a}{0}%
\setcounter{b}{0}%
...
}
Full example for completeness (and with larger fonts):
\documentclass{article}
\usepackage{calc}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{verbatim}
\newcommand{\piepart}[5]
{
\draw[thick,fill=#4] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult
\pgfmathtruncatemacro{\trunc}{\midangle}
\ifthenelse{\trunc < 90}{
\draw (\midangle:1) node[above right]{#3};
}
{
\ifthenelse{\trunc < 180}{
\draw (\midangle:1) node[above left]{#3};
}
{
\ifthenelse{\trunc < 270}{
\draw (\midangle:1) node[below left]{#3};
}
{
\draw (\midangle:1) node[below right]{#3};
}
}
}
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
\let\temp\pgfmathresult
\pgfmathparse{max(\temp,-0.5) + 0.8}
\let\innerpos\pgfmathresult
\node at (\midangle:0.8) {#5};
}
\newcounter{a}
\newcounter{b}
\newcommand{\piechart}[1]
{
\setcounter{a}{0}%
\setcounter{b}{0}%
\foreach \p/\mcolor/\mname in #1
{
\setcounter{a}{\value{b}}
\addtocounter{b}{\p}
\piepart{\thea/100*360}
{\theb/100*360}
{\mname}{\mcolor}{\p\%}
}
}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\tikzstyle{every node}=[font=\footnotesize]
\piechart{{75/gray/A, 18/green/B, 7/red/C}}
\end{tikzpicture}
\begin{tikzpicture}[scale=1.5]
\tikzstyle{every node}=[font=\footnotesize]
\piechart{{75/gray/A, 18/green/B, 7/red/C}}
\end{tikzpicture}
\end{document}
Best Answer
The package you need is
amsthm
(besides the recommendedamsmath
).Add
\usepackage{amsthm}
and all will go flawlessly.