2

I cut-and-paste a basic example from the tikzcd manual and keep getting error messages. Here is a minimal example:

\documentclass{beamer}
\usepackage{tikz-cd}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{frame}
  $$
  \begin{tikzcd}
%    \\
    & C
  \end{tikzcd}
  $$
\end{frame}
\end{document}

This example works, BUT if uncomment the \ line I get the error message

\pgf@matrix@no@eom@found ->\cr 
                               \noalign {\vskip \pgf@y \ifpgf@matrix@fixed \...
l.14 \end{frame}

And if I keep hitting "return" on these errors messages, I get more and different ones:

? 
! Missing } inserted.
<inserted text> 
                }
l.13 \end{frame}

? ! Missing } inserted. <inserted text> } l.13 \end{frame}

? ! Missing \cr inserted. <inserted text> \cr l.13 \end{frame}

? ! Misplaced \cr. <inserted text> \cr

l.13 \end{frame}

The code is taken from the manual so I'm confused. In case this matters, I am using TexLive 2017/Debian.

Thanks for your help!

underflow
  • 559
  • 3
    Better use \[ ... \] instead of $$ ... $$ (learn why). And then, according to this discussion, using \begin{frame}[fragile] should help – Jasper Habicht Jan 26 '22 at 17:53
  • With a recent installation of TeXlive, your sample code gives no errors. What does the log file say about versions? Mine says: pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021), LaTeX2e <2021-11-15> patch level 1, tikz-cd 2021/05/04 v1.0 – gernot Jan 26 '22 at 17:57
  • @habicht: \begin{frame}[fragile] solves the problem! Thanks! What does this do? – underflow Jan 26 '22 at 18:07
  • @gernot: My texlive says This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex 2019.7.13) 26 JAN 2022 13:00 (and how do you "shade" a line of text? I tried "Ctrl-L" to no avail) – underflow Jan 26 '22 at 18:08
  • Updating (La)TeX probably solves your problem. For the shading, enclose the text in backticks ``` – gernot Jan 26 '22 at 19:39

1 Answers1

5

You have two possibilities that I'll show in two different frames.

\documentclass{beamer}
\usepackage{tikz-cd}
\usepackage[english]{babel}

\begin{document}

\begin{frame}

[ \begin{tikzcd}[ampersand replacement=&amp;] A \arrow[r] &amp; B \arrow[d]\ &amp; C \end{tikzcd} ]

\end{frame}

\begin{frame}[fragile]

[ \begin{tikzcd} A \arrow[r] & B \arrow[d]\ & C \end{tikzcd} ]

\end{frame}

\end{document}

The first way is more efficient, but a bit annoying; the second way is slower because it requires writing to a file an inputting it.

enter image description here

Why the need for ampersand replacement=\&? Because when a non fragile frame code is read in, you're actually passing the contents as the argument to a command and tikz-cd then requires the trick. In the fragile case, the frame code is input from a file so it's not regarded as the argument to a command.

Two more comments: never use $$ in LaTeX. Also latin1 is really obsolete: save your files in UTF-8 and you'll be happier.

egreg
  • 1,121,712
  • Thanks! Unfortunately the first solution gives the same error message. Also, when I replace \usepackage[latin1]{inputenc} with \usepackage[UTF-8]{inputenc} I got the error message "LaTeX Error: File `UTF-8.def' not found." – underflow Jan 26 '22 at 19:00
  • @underflow Saver your files as UTF8 and forget about inputenc. About the error, I can say nothing: I don't get it. – egreg Jan 26 '22 at 20:59