Home > Software design >  set latex variable and reuse it
set latex variable and reuse it

Time:05-30

I want to define a variable for example ``name'', then reuse it in other place in other macros or other part of text.

but following codes do not work correctly.

\documentclass[10pt,a4paper]{article}

\newcommand{\name}[1]{#1}
\newcommand{\showname}{\name}

\begin{document}

\name{Kiana}

%   My name is ``\showname''

\end{document}

CodePudding user response:

You can do it like this:

\documentclass[10pt,a4paper]{article}

\newcommand{\name}[1]{\def\showname{#1}}

\begin{document}

\name{Kiana}

   My name is ``\showname''

\end{document}
  • Related