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.

4
  • 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
    Commented Dec 3, 2017 at 22:23
  • I apologize for not telling you exactly. I edited the problem and added new image. Can you check?
    – Özgür
    Commented Dec 3, 2017 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
    Commented Dec 4, 2017 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
    Commented Dec 4, 2017 at 4:59

1 Answer 1

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

4
  • The explanation you wrote provided me with good information.
    – Özgür
    Commented Dec 3, 2017 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
    Commented Dec 3, 2017 at 21:30
  • I edited the problem. Can you check?
    – Özgür
    Commented Dec 3, 2017 at 21:40
  • I took your precious time.
    – Özgür
    Commented Dec 4, 2017 at 5:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .