2

Few \newcommands defined in my standalone .tex file containing tikz figure is not recognized in the main beamer .tex file. Please point out what extra lines should I write to make it work.

Here is the standalone file:

% H-atom energy diagram: 1-photon excited 1-photon ionization

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.pathmorphing, patterns}

% New commands
\newcommand{\ket}[1]{$\left|#1\right\rangle$}
\newcommand{\Om}[1]{\small $\omega_{#1}$}
\newcommand{\De}[1]{$\Delta_{#1}$}
\newcommand{\ta}[1]{$\tau_{#1}$}

\begin{document}
    \begin{tikzpicture}[
        scale=0.5,
        level/.style={thick},
        virtual/.style={thick,densely dashed},
        trans/.style={thick,<->,shorten >=0pt,shorten <=0pt,>=stealth},
        ionize/.style={thick,->,shorten >=0pt,shorten <=0pt,>=stealth},
        decay/.style={thin,->,decorate,decoration=snake,shorten >=0pt,shorten <=0pt,>=stealth}
        ]
        % Draw the energy levels
        \draw[level] (1cm,4em) node[left]{\scriptsize{13.6eV}} -- (6cm,4em) node[right]{\ket{c}};
        \draw[level] (1cm,0em) node[left]{\scriptsize{10.2eV}} -- (6cm,0em) node[right]{\ket{2p}};
        \draw[level] (1cm,-10em) node[left]{\scriptsize{0eV}} -- (6cm,-10em) node[right]{\ket{1s}};

        % Draw the transitions
        \draw[trans] (3cm,-10em) -- (3cm,0em) node[midway,left] {\scriptsize{122nm}};
        \draw[ionize] (3cm,0em) -- (3cm,10em) node[left] {\scriptsize{122nm}};
        \draw[ionize] (5cm,0em) -- (5cm,8em) node[right] {\scriptsize{355nm}};
        \draw[decay] (3cm,0em) -- (5cm,-3em) node[below] {\scriptsize{\ta{sp}=1.6ns}};
    \end{tikzpicture}
\end{document} 

Here is the excerpt from the main file:

\documentclass{beamer}
\usetheme{Boadilla} 
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{subfigure}
\usepackage{epstopdf}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{external}
%\tikzexternalize[prefix=i/]
\setbeamertemplate{caption}[numbered]
\epstopdfsetup{outdir=./}

\begin{document}
\title{Main title}
\institute{KU-IAE}
\date{\today}

\frame{\titlepage}

\frame{\frametitle{Table of Contents}\tableofcontents}

\section{This section}
\frame{\frametitle{This section}

    \begin{wrapfigure}{R}{0.4\textwidth}
        \begin{center}
        \includestandalone[width=0.4\textwidth]{figs/2_level_1ph_excite_1ph_ion}
%       \includegraphics[width=0.3\textwidth]{figs/H_energy_diagram_1_ph}
        \end{center}
        \caption{this caption}
    \end{wrapfigure}
    Text text text text,
    \begin{itemize}
        \item Text text text text
        \item Text text text text
        \item Text text text text
    \end{itemize}
}
\end{document}

The error message excerpt:

! Undefined control sequence. l.23 ...ize{13.6eV}} -- (6cm,4em) node[right]{\ket {c}}; ?

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jun 11 '14 at 12:03
  • Pardon me if the format of my post was illegible. I have edited it into compilable form. – mohan_das Jun 11 '14 at 12:29
  • No problem at all, we do not punish here ;-) – user31729 Jun 11 '14 at 12:33
2

\includestandalone command crops all preamble and starts processing standalone file after \begin{document}. So, if you include all \newcommand after \begin{document}, all of them will be available into main file.

You also need to include all packages and libraries used in your standalone file on main file preamble.

  • Thank you, Ignasi. I now understand the matter. It solved my problem. – mohan_das Jun 11 '14 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.