# Use variables like #1 in math [closed]

I'm writing this small \newcommand, and I want to send numbers as parameters. But since the math mode always tries to interpret the # in a different way. I don't know what to do. Here is what I have tried so far:

\newcommand{\scoring}[1]{%
\begin{center}
$K^1=$#1      % this does work, however it looks ugly
$K^1=#1$      % does work
$K^1=\#1$     % does not work
$K^1=\{#1}$   % does also not work
\end{center}
}


I call this command with this:

\scoring{4}


So a 4 should appear.

## closed as off-topic by Werner, Raaja, Stefan Pinnow, egreg, Marcel KrügerMar 5 at 21:37

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Off-topic: Why you have to use \begin{center} $a=b$ \end{center} when you already have $a=b$? – user156344 Mar 5 at 17:02
• $K^1=#1$ should actually work in that it would output K^1=4. Can you show us a complete example document where that goes wrong, please? I agree with JouleV that \begin{center}$...$\end{center} looks suspiciously like you want $...$ or $$...$$ or align.... – moewe Mar 5 at 17:05
• \documentclass{article} \newcommand{\scoring}[1]{$K^1=#1$} \begin{document} \scoring{4} \end{document} works flawlessly for me – sheß Mar 5 at 17:08
• I'm voting to close this question as off-topic because the problem cannot be replicated. – Werner Mar 5 at 19:52

\documentclass[a4paper]{article}

\newcommand{\scoring}[1]{%
\begin{center}%
$K^1=#1$\\%
$K^1=\{#1\}$\\%
$K^1=\string###1$\\%
$K^1=\{\string###1\}$\\%
$K^1=\{\##1\}$\\%
$K^1=\{\sharp#1\}$%
\end{center}%
}

\begin{document}

\verb|\scoring{4}|:

\scoring{4}

\verb|\scoring{5}|:

\scoring{5}

\end{document}


• Better use \# (or maybe \sharp) instead of \string##. – Henri Menke Mar 5 at 20:55