2

I have this code that gives me two problems:

  1. y and x are displayed incorrectly in the first and third row of the eqnarray, like if they had a \rm in front of them, why?
  2. it gives me

    main.tex:91 Undefined control sequence.
    <argument> \D 
    ^0  
    l.91 \Gamma(\Dz
    (t)\to f)&=&\frac{1}{2}\rm{e}^{-\tau}\left|\Af\right|^2 \{ \l...
    The control sequence at the end of the top line
    of your error message was never \def'ed. If you have
    misspelled it (e.g., `\hobx'), type `I' and the correct
    spelling (e.g., `I\hbox'). Otherwise just continue,
    and I'll forget about whatever was undefined.
    

have I forgot to declare something? Here is my example code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xfrac}
\title{ aaa }
\author{FLR }
\date{June 2011}
%% %%%%%%%%%%%%%%%%%%%%%%%
%% Packages to be used
%% %%%%%%%%%%%%%%%%%%%%%%% 
\usepackage{amsfonts} %for integers using \mathbb{Z}
\usepackage{lineno}  % for line numbering during review
\usepackage{graphicx}  % to include figures (can also use other packages)
\usepackage{caption}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{subcaption}
\usepackage{wrapfig,booktabs}
\usepackage{xfrac}
%\usepackage{epstopdf}
\usepackage{xspace}     % 
% predefined symbold
\usepackage{multirow}
\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\usepackage{blindtext}
\usepackage{color}
\usepackage{colortbl}
\usepackage{amsmath} % Adds a large collection of math symbols
\usepackage{ifthen} % for conditional statements
%\graphicspath{{./}} % Make Latex search fig subdir for figures
% %%%%%%% CHOOSE --------
\newboolean{pdflatex}
%\setboolean{pdflatex}{false} % use this if using eps figures
\setboolean{pdflatex}{true} % use this if using non-eps figures
%

\newboolean{articletitles}
\setboolean{articletitles}{true} % False removes titles in references

\newboolean{uprightparticles}
\setboolean{uprightparticles}{false} %Set to true to get roman particle symbols

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{upgreek} % Adds in support for greek letters in roman typeset

\usepackage{hyperref}    % Hyperlinks in references
\usepackage[all]{hypcap} % Internal hyperlinks to floats.
\usepackage{natbib}
\usepackage{graphicx}


\def\CP  {\ensuremath{C\!P}\xspace}
\def\CPV  {\ensuremath{C\!PV}\xspace}
\def\C  {\ensuremath{C}\xspace}
\def\P  {\ensuremath{P}\xspace}
\newcommand{\Ap}  {\ensuremath{{\cal A}_{\rm{P}}}\xspace}
\newcommand{\Apnoef}  {\ensuremath{{\cal A}_{\rm{P~no~eff}}}\xspace}
\newcommand{\Acp}  {\ensuremath{{\cal A}_{\rm{CP}}}\xspace}
\newcommand{\Araw}  {\ensuremath{{\cal A}_{\rm{RAW}}}\xspace}
\newcommand{\AGamma}  {\ensuremath{{\cal A}_{\rm{\Gamma}}}\xspace} %
\newcommand{\Af}  {\ensuremath{{\cal A}_f}\xspace}
\newcommand{\Afb} {\ensuremath{\bar{\cal A}_f}\xspace}
\newcommand{\Am}  {\ensuremath{{\cal A}_m}\xspace}
\newcommand{\Adir}{\ensuremath{{\cal A}^{\rm dir}}\xspace}
\def\DDbar {\ensuremath{\kern -0.1em \stackrel{\kern 0.1em \textsf{\fontsize{5pt}{1em}\selectfont(---)}}{D}\kern -0.3em}\xspace}
\def\Dz{\ensuremath{\D^0}\xspace}
\begin{document}

\maketitle



% (4) %
\begin{eqnarray}
\label{eq:p-1}
\Gamma(\Dz(t)\to f)&=&\frac{1}{2}\rm{e}^{-\tau}\left|\Af\right|^2 
\{\left(1+|\lambda_f|^2\right)\cosh(y\tau)+\left(1- |\lambda_f|^2\right)\cos(x\tau)\nonumber\\
&+&2\Re(\lambda_f)\sinh(y\tau)-2\Im(\lambda_f)\sin(x\tau)\},\nonumber\\
\Gamma(b(t)\to f)&=&\frac{1}{2}\rm{e}^{-\tau}\left|\bar\Af\right|^2 
\{\left(1+|\lambda^{-1}_f|^2\right)\cosh(y\tau)+\left(1- |\lambda^{-1}_f|^2\right)\cos(x\tau)\nonumber\\
&+&2\Re(\lambda^{-1}_f)\sinh(y\tau)-2\Im(\lambda^{-1}_f)\sin(x\tau)\},
\end{eqnarray}

\end{document}
Mico
  • 506,678
leoredi
  • 781
  • It would appear that the control sequence \D isn't defined. – Mico Aug 11 '13 at 23:55
  • 1
    Use \def\Dz{\ensuremath{D^0}\xspace}. Note {D^0} instead of {\D^0}. As a side note don't use eqnarray. Use align or align* from amsmath. –  Aug 11 '13 at 23:58

1 Answers1

4

The title of your posting suggests that you're encountering problems with the eqnarray environment. Actually, neither of the problems is related to eqnarray directly.

  • The term \D in the definition of \Dz should really be just D, right?

  • The reason why the terms x and y in the original form of your example show up in upright rather than math-italic form is that \rm does not take an argument. The command \rm is a switch, i.e., all letters in the current group following \rm will get typeset in the upright-roman font shape; this group does not end with the } after {e}. What makes the issue a bit difficult to diagnose at first is that there are only three (latin) letters on the first and third lines subject to the action of \rm: e, x, and y; all other material is either a symbol (e.g., a parenthesis), a greek symbol, or gets typeset in upright roman form anyway because it's a math operator (e.g., cosh). Use either \mathrm{e} or \text{e}, and the problem goes away.

Note that your code features a number of issues that, collectively, make it both difficult to read and debug and less than typographically satisfactory.

  • Don't use the heavily deprecated and typographically suspect eqnarray environment. Use the align environment instead; it's an environment provided by the amsmath package, which is already loaded in your code. In case you harbor any doubts about the inferiority of eqnarray, please read the posting eqnarray vs align and the associated answers.

  • The second and fourth lines should be indented quite a bit relative to the first and third lines; do not align the = sign of the first and third lines with the + symbols of the second and fourth lines.

  • A number of packages get loaded more than once. Sooner or later this is going to cause trouble.

  • Don't use the deprecated \rm and \cal directives in math mode. Use \text{...} and \mathcal{...} instead.

  • The many \xspace directives don't do anything at all in math mode. Omit them entirely.

  • The use of \left and \right to influence the size of the parentheses leads to unevenly-sized parentheses across (logically) related terms. Better to use \bigl and \bigr instead -- at least in the case of the equations at hand. Also, use \Big (note the uppercase B) to set the sizes of the curly braces -- they really need to be bigger than any of the round parentheses.

With these issues addressed, and the preamble simplified to make it more of a minimal working example, one gets this:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{upgreek} % Adds in support for greek letters in roman typeset

\def\CP  {\ensuremath{C\!P}}
\def\CPV  {\ensuremath{C\!PV}}
\def\C  {\ensuremath{C}}
\def\P  {\ensuremath{P}}
\newcommand{\Ap}  {\ensuremath{\mathcal{A}_{\text{P}}}}
\newcommand{\Apnoef}  {\ensuremath{\mathcal{A}_{\text{P~no~eff}}}}
\newcommand{\Acp}  {\ensuremath{\mathcal{A}_{\text{CP}}}}
\newcommand{\Araw}  {\ensuremath{\mathcal{A}_{\text{RAW}}}}
\newcommand{\AGamma}{\ensuremath{\mathcal{A}_{\Gamma}}} %
\newcommand{\Af}  {\ensuremath{\mathcal{A}_f}}
\newcommand{\Afb} {\ensuremath{\bar\mathcal{A}_f}}
\newcommand{\Am}  {\ensuremath{\mathcal{A}_m}}
\newcommand{\Adir}{\ensuremath{\mathcal{A}^{\text{dir}}}}
\def\DDbar {\ensuremath{\kern -0.1em \stackrel{\kern 0.1em 
       \textsf{\fontsize{5pt}{1em}\selectfont(---)}}{D}\kern -0.3em}}
\def\Dz{\ensuremath{D^0}}
\begin{document}

\begin{align}
\label{eq:p-1}
\Gamma(\Dz(t)\to f)
&=\frac{1}{2}\text{e}^{-\tau}\bigl|\Af\bigr|^2 \Big\{     
  \bigl(1+|\lambda_f|^2\bigr)\cosh(y\tau)+
  \bigl(1-|\lambda_f|^2\bigr)\cos(x\tau)\nonumber\\
&\qquad +2\Re(\lambda_f)\sinh(y\tau)-2\Im(\lambda_f)\sin(x\tau)
  \Big\},\nonumber\\
\Gamma(b(t)\to f)
&=\frac{1}{2}\text{e}^{-\tau}\bigl|\bar\Af\bigr|^2 \Big\{ 
  \bigl(1+|\lambda^{-1}_f|^2\bigr)\cosh(y\tau)+
  \bigl(1-|\lambda^{-1}_f|^2\bigr)\cos(x\tau)\nonumber\\
&\qquad +2\Re(\lambda^{-1}_f)\sinh(y\tau)-2\Im(\lambda^{-1}_f)
  \sin(x\tau)\Big\}.
\end{align}

\end{document}
Mico
  • 506,678
  • I'd prefer \mathrm or \textnormal instead of \text for textual sub/superscripts. All those \ensuremath commands are useless, since these commands are to be used in math mode; I wouldn't recommend using \def. And \bar\mathcal{A}_f is wrong: \bar{\mathcal{A}}_f will do right. – egreg Aug 12 '13 at 08:20
  • 1
    @egreg - I had noticed the \bar\mathcal{A}_f as well. However, it doesn't throw an error in the present example and even creates the same output as \bar{\mathcal{A}}_f, so I decided to omit from the litany of things the OP really should address. – Mico Aug 12 '13 at 10:12