1

MWE

\documentclass[11pt,a4paper]{exam}

\lhead{\fbox{\textbf{LEFT}}}
\newcommand[\macrol]{\lhead{\fbox{\textbf{LEFT}}}} 

\rhead{\fbox{\textbf{RIGHT}}}
\newcommand[\macrol]{\lhead{\fbox{\textbf{RIGHT}}}}

\begin{document}
First Page
\newpage

The content of lhead is \macrol.

The content of rhead is  \macror.

\end{document}

My purpose is to call \lhead or \rhead from anywhere in the text with a macro.

enter image description here

Thanks.

  • I'm sorry but I don't understand what you want. There's no problem to put a macro inside the \lhead command. How do you want the choice to be made? – Alan Munn Dec 3 '17 at 22:23
  • I apologize for not telling you exactly. I edited the problem and added new image. Can you check? – Özgür Dec 3 '17 at 22:32
  • I'm sorry but I still don't understand. Do you want to define a macro that saves the value of \lhead and \rhead which can then be used in the document. – Alan Munn Dec 4 '17 at 0:06
  • I want to write that I'm sorry again. No I do not want to define a macro without saving the \lhead and \rhead values ​​that can be used later on the document. I want to define a macro but this macro will be to read the contents of \lhead and \rhead. – Özgür Dec 4 '17 at 4:59
2

Here's a simple way to do what you want:

\documentclass[11pt,a4paper]{exam}
\newcommand\savelhead[1]{\gdef\savedlhead{#1}\lhead{\savedlhead}}
\newcommand\saverhead[1]{\gdef\savedrhead{#1}\rhead{\savedrhead}}
\savelhead{LeftHead}
\saverhead{RightHead}

\begin{document}
First Page
\newpage
Booklet Choice \savedlhead\ or \savedrhead.
\end{document}

output of code

  • The explanation you wrote provided me with good information. – Özgür Dec 3 '17 at 21:25
  • 1
    @Özgür if the answer helped you it's helpful to "Accept" it by clicking on the green checkmark beside it. – Alan Munn Dec 3 '17 at 21:30
  • I edited the problem. Can you check? – Özgür Dec 3 '17 at 21:40
  • I took your precious time. – Özgür Dec 4 '17 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.