I had a .tex file which had the following magical code to translate the adadi page number to its roman equivalent.
\makeatletter
\newcommand{\aresame}[2]{%
\aresame@massage\aresame@tempa{#1}%
\aresame@massage\aresame@tempb{#2}%
\ifx\aresame@tempa\aresame@tempb
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\def\aresame@massage#1#2{%
\begingroup\let\@xp\expandafter\let\@nx\noexpand
\everyeof{}%
\catcode`{=9 \catcode`}=9
\catcode`<=1 \catcode`>=2
\begingroup\edef\x{%
\endgroup\@nx\scantokens{\def\@nx\1<#2>\@nx\empty}%
}\x
\uppercase\@xp{\@xp\endgroup\@xp\def\@xp#1\@xp{\1}}%
}
\makeatother
accompanying with the following code:
\def\myadadipage{\getpagerefnumber{lastpreamblepage}} %this reads the page number in *adadi*, since we used \pagenumbering{adadi} for the preamble part of the document.
\newcounter{searchforadadi}
\loop
\relax%
\ifnum\value{searchforadadi} < 1000
\addtocounter{searchforadadi}{1}%
\aresame{\myadadipage}{\adadi{searchforadadi}}{\xdef\myromanpage{\roman{searchforadadi}}}{}%
\repeat
now I can use \myromanpage anywhere in my document, without any problem.
But
My question arises as:
"How can I move these code to a supplementary
.clsfile and put them exactly inside another command, I am curious to see how can I define a command, like this one, but just works, internally/locally inside another command?"
Since when I simply copy all these codes from the .tex file to the .cls file, where I need to use the command \aresame inside a definition of another command, say \@setabstract, used to typeset/pageset the English abstract/summary page of the work,
\def\@setabstract{%
\newcommand{\aresame}[2]{%
\aresame@massage\aresame@tempa{#1}%
\aresame@massage\aresame@tempb{#2}%
\ifx\aresame@tempa\aresame@tempb
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\def\aresame@massage#1#2{%
\begingroup\let\@xp\expandafter\let\@nx\noexpand
\everyeof{}%
\catcode`{=9 \catcode`}=9
\catcode`<=1 \catcode`>=2
\begingroup\edef\x{%
\endgroup\@nx\scantokens{\def\@nx\1<#2>\@nx\empty}%
}\x
\uppercase\@xp{\@xp\endgroup\@xp\def\@xp#1\@xp{\1}}%
}
\newpage
\thispagestyle{empty}
\if@bachelor
\else
\begin{framed}
Number of Pages:
\xdef\myadadipage{\getpagerefnumber{lastpreamblepage}}
\newcounter{searchforadadi}
\loop
\relax%
\ifnum\value{searchforadadi} < 1000
\addtocounter{searchforadadi}{1}%
\aresame{\myadadipage}{\adadi{searchforadadi}}{\xdef myromanpage{\roman{searchforadadi}}}{}%
\repeat
\pageref{LastPage} + \myromanpage
\end{framed}}%end of set abstract
I will receive an error like:
! Illegal parameter number in definition of \@setabstract.
<to be read again>
1
l.697 \aresame@massage\aresame@tempa{#1
}%
?
Let me clear that, if I paste these codes outside the definition it is globally accessible and no errors found! But I wanted to know if I can have them local just for \@setabstract function.
Thanks in advance!
This question is sequel to another TeX.SX question, which could be found here.
\@setabstract. What shall I do? – Omid Ghayour Sep 16 '16 at 15:56\makeatletterand\makeatotherand they should work the same way do not put them inside another definition – David Carlisle Sep 16 '16 at 15:59.clspackage. for the magical code! :) – Omid Ghayour Sep 16 '16 at 20:36\@setabstractcommand which gives me the error. – Omid Ghayour Sep 16 '16 at 20:53