I need to redefine the \percent
unit in siunitx
so that it reads "percent" in running text but remains as "%" in tables and equations. I assume there must be an option for this, but I looked into the package documentation and couldn't find any.
1 Answer
I do not know if there is a method to decide if you are in a table or not. What does exist is a way to check if your are in math mode or not; you can do something like this:
\documentclass{article}
\usepackage{siunitx}
\DeclareSIUnit{\textpercent}{percent}
\newcommand{\autopercent}{\ifmmode\,\si{\percent}\else\si{\textpercent}\fi}
\begin{document}
This is in text: 12~\autopercent; and you have to use \verb|{}| after the
command as in 5~\autopercent{} if you have a space after. In equation:
\[
A = 14\autopercent
\]
\end{document}
\light
command as\newcommand{\light}[1][per-mode = symbol-or-fraction]{\SI[#1]{299792458}{\meter\per\second}}
, which chooses whether to write the m/s units as an inline or a displayed fraction according to context, and I thought something similar might be possible here.\light
use the indicatedper-mode
by default, and you can override it. No automatic switching.