1

I am designing gamecards in LaTeX

Everything is going pretty ok so far but when i try to insert the %-sign for a question about percentages my file keeps giving errors. I tried putting the percentage between dollarsigns because i know just % will make it a 'remark' and that the dollarsign makes it 'mathematical data'.

Whats the reason for the error?

P.s. the error says: file ended while scanning use of \kaart. ... 

Codesample:

{\kaart{Bekijk statistiek kaart F: 

Schat het percentage mensen dat als lievelingseten spaghetti opgaven, je mag er slechts $ 2% $ langs zitten. } { $ 11% $}}
  • 1
    % is a comment character, leading to errors (in most cases). You want to use \% or, better use siunitx and \SI{11}{\percent} for example. There's \textpercent also –  May 24 '16 at 14:37
  • 1
    Is this only with the %-sign or is are there more signs i should be aware of that have the same 'problem' – Michelle_B May 24 '16 at 14:39
  • 1
    (La)TeX knows some command symbols like %, #, _, $ etc. They all must be escaped with , i.e. \%, \#, \_, \$ to get their literal meaning, otherwise, they act as commands, switching to a certain behaviour, like $ entering the math mode –  May 24 '16 at 14:41
  • That is if you want to use them as a textsymbol not a command right? – Michelle_B May 24 '16 at 14:43
  • 1
    Yes, exactly this way. To prevent an accidental misuse, there are some commands that display those characters, like \textpercent, \textdollar –  May 24 '16 at 14:44
  • This should be explained in every introduction to LaTeX that deserves its name. – cgnieder May 24 '16 at 15:26
  • I have to correct myself: There's no \textpercent command, apparently –  May 24 '16 at 15:50

1 Answers1

8

Don't use % if you want to write the % character directly.

The % character is reserved to indicate a comment after which everything is ignored. This is no problem at the end of a line, but the % should not occur in between, say, $ 11 % $, because this way TeX has entered math mode which is not correctly closed (unless there's a stray $ following in one of the next lines. So this most likely leads to errors.

Use \% or for better spacing, use the siunitx package and say \SI{11}{\percent} for example.

Here's some example code:

\documentclass{article}

\usepackage{siunitx}
\begin{document}

% How not to be seen

There are some ways to type a literal \% character:

\begin{itemize}
  \item Say \verb!\%! and it will print \%
  \item Say \textbackslash verb!\%! in verbatim mode and it will print \verb!%!
  \item Say \verb!\SI{11}{\percent}! and it will print \SI{11}{\percent}
\end{itemize}

\end{document}

enter image description here