2

I would like to call the macro \PsalmY{} where 'Y' is a number in Roman Capital numerals (this macro display the Psalm n°Y). For example, \PsalmII{} will display Psalm 2.

Therefore I have created a macro :

\newcommand{\Psalmus}[1]{\csname Psalm\romannumeral#1\endcsname}

But the macro \romannumeral output is a Roman numeral in small letters. I have try thefolling code but it is not working :

\newcommand{\Psalmus}[1]{\csname Psalm\MakeUppercase{\romannumeral#1}\endcsname}

I can decide to use small Roman numeral but it will be less readable.

JBOP
  • 97
  • Unfortunately, I don't understand their solution, I am not yet very familiar with Latex. – JBOP Apr 22 '22 at 20:17
  • 1
    Can you explain better what you're going to do? If you want to call \PsalmII, just do it. – egreg Apr 22 '22 at 20:32

4 Answers4

6

You need to first expand \romannumeral and then apply \uppercase. It is easier using an auxiliary macro.

\makeatletter
\newcommand\@Psalm{Psalm}
\newcommand\Psalmus[1]{\uppercase\expandafter{\expandafter\csname\expandafter\@Psalm\romannumeral#1\endcsname}}
\makeatother
5

According to you previous question A database for a Psalter and self-answer, you have something like

\newcommand{\PsalmI}{%
  <text of Psalm 1>
}
\newcommand{\PsalmII}{%
  <text of Psalm 2>
}

I removed the [1] from the code you showed, because it's really wrong as you don't have an argument.

Now you want an interface like \Psalmus{22} for typesetting Psalm 22. That's possible with standard (internal) commands of LaTeX:

\makeatletter
\newcommand{\Psalmus}[1]{\csname Psalm\@Roman{#1}\endcsname}
\makeatother

Let's try, with an abridged version.

\documentclass{article}
\usepackage[T1]{fontenc}

% this will probably be in a separate file that you \input \newcommand{\PsalmI}{% <text of Psalm 1> } \newcommand{\PsalmII}{% <text of Psalm 2> } \newcommand{\PsalmXXII}{% <text of Psalm 22> } %%%

\makeatletter \newcommand{\Psalmus}[1]{\csname Psalm@Roman{#1}\endcsname} \makeatother

\begin{document}

\Psalmus{2}

\Psalmus{22}

\end{document}

enter image description here

On the other hand, I'd do it in a different way, without back and forth conversion into Roman numbers.

\documentclass{article}
\usepackage[T1]{fontenc}

% this will probably be in a separate file that you \input \makeatletter \newcommand{\definepsalm}[2]{@namedef{psalm#1}{#2}} \newcommand{\Psalmus}[1]{@nameuse{psalm#1}} \makeatother

\definepsalm{1}{% <text of Psalm 1> } \definepsalm{2}{% <text of Psalm 2> } \definepsalm{22}{% <text of Psalm 22> } %%%

\begin{document}

\Psalmus{2}

\Psalmus{22}

\end{document}

egreg
  • 1,121,712
1
\makeatletter
%% \Psalm<stuff not in braces>{<number>}
%% ->  <stuff not in braces>\Psalm<uppercased-roman-representation of <number>>
%% (<stuff not in braces> may be empty.)
\@ifdefinable\Psalm{\long\def\Psalm#1#{\@Psalm{#1}}}%
\newcommand\@Psalm[2]{\expandafter\exchange\expandafter{\csname Psalm\@Roman{#2}\endcsname}{#1}}%
\newcommand\exchange[2]{#2#1}%
\makeatother

\documentclass{article}

%\newcommand*\PsalmII{%
\Psalm\newcommand*{2}{%
  Why do the nations rage\\%
  and the peoples plot in vain?\\%
  \dots
}%

%\newcommand*\PsalmXXIII{%
\Psalm\newcommand*{23}{%
  The Lord is my shepherd; I shall not want.\\%
  He makes me lie down in green pastures.\\%
  \dots
}%

\begin{document}

\noindent\Psalm{2}

\bigskip

\noindent\Psalm{23}

\bigskip

\noindent\PsalmII

\bigskip

\noindent\PsalmXXIII

\end{document}

enter image description here

Ulrich Diez
  • 28,770
0

Define 1 to 100:

\documentclass{article}
\ExplSyntaxOn
\cs_new_eq:NN \Repeat \prg_replicate:nn
\ExplSyntaxOff

\newcounter{rnum} \setcounter{rnum}{1}

\Repeat{100}{\expandafter\edef\csname Psalm\Roman{rnum}\endcsname{Psalm \thernum} \stepcounter{rnum} }

\begin{document} \PsalmI

\PsalmII

\PsalmIV

\PsalmVII

\PsalmIX

\PsalmX

\PsalmXV

\PsalmXXI

\PsalmXLVII

\PsalmLXXII

\PsalmXCIX

\PsalmC \end{document}

Tom
  • 7,318
  • 4
  • 21