I'm looking for a way to get the following done

I want to have a command


with the following definition

\def\setcitation#1#2{\lowercase{\expandafter\gdef\csname mycommoncitation#1\endcsname}{#2}}

Essentially, what it does is each time it is called with arguments xXx and yyy, it creates a new command


defined as


Now, given an input, xxX, I would like to get yyy out. So what has to happen: convert xxX to lowercase xxx, call \mycommoncitationxxx

I tried doing this as follows:


And as follows:

\newcommand\getcitation[1]{\lowercase{\expandafter\gdef\csname mycommoncitation#1\endcsname}}

However niether work.

For the first part (the definition of my setcitation command) I based my solution on build a capitalized CS from a lowercase string and to give it a definition

For the second part, I don't find any help yet.

Complete example, that also shows how I want to use these commands:



\getcitationifexistsotherwiseinput{Foo} %My expectation: Bar
\getcitationifexistsotherwiseinput{foo} %my expectation: Bar
\getcitationifexistsotherwiseinput{boo} %my expectation: boo
%Now I want a command that returns 
% \getcitation{FOO} 

\cite{\getcitation{foo}} %my expectaiton: "undefined citation Bar"

here, in the line \cite{...} things start to go wrong.

  • 1
  • lowercase is not expandable so does not work inside \cite if you don't mind enumerating all the letters (eg if you only allow a-z, not accented letters) then it is possible to write an expandable version. Or simpler use a modified command say \lccite that applies lowercase then \cite` – David Carlisle Jan 20 '17 at 13:57
  • The problem with that is that I cometimes want to use it in the form \cite{something,\getcitation{somethingelse}}, SO I'ld basically ahve to patch the entire cite command... – BartBog Jan 20 '17 at 14:51
  • @BartBog well then you can use the expandable lowercase commands in the question that Steven linked – David Carlisle Jan 20 '17 at 15:43

You need an expandable version of \lowercase:


  \prop_gput:Nxn \g_bartbog_citations_prop { \str_lowercase:n { #1 } } { #2 }
  \prop_item:Nf \g_bartbog_citations_prop { \str_lowercase:n { #1 } }

\cs_generate_variant:Nn \prop_gput:Nnn { Nx }
\cs_generate_variant:Nn \prop_item:Nn { Nf }
\prop_new:N \g_bartbog_citations_prop





\bibitem{Bar} Whatever



I used a property list for compactness.

enter image description here

  • When I try this, I get a lot of LaTeX Warning: Citation `' on page 1 undefined on input line 28. errors and getctation does not print anything... – BartBog Jan 25 '17 at 9:25
  • Also: could you extend your answer with a command like getcitationifexistsotherwiseinput in my question. It is not clear to me how to check existance in explsyntax – BartBog Jan 25 '17 at 9:28
  • @BartBog What are you expecting? You're passing something to \cite which it doesn't know. What can be done is making the message something like LaTeX Warning: Citation `MISSING' on page 1 undefined on input line 28, not much more. – egreg Jan 25 '17 at 12:05
  • What I mean is that when I run exactly your code, I don't get Bar Bar Bar [1] [1] [1] but [?] [?] [?]. I.e., it does not seem to be working. Concretely, if I remove the \str_lower_case:n from getcitation, One of the \getcitations works... – BartBog Jan 25 '17 at 12:23
  • @BartBog Are you sure you have an up-to-date TeX system? – egreg Jan 25 '17 at 12:25

I just posted another answer to Expandably change letter case and use inside \csname, without a package.

That answer can be found at https://tex.stackexchange.com/a/349895/118714 .

That answer contains a routine \UD@ExpandableLowercase which delivers lowercasing of those 26 catcode-11(letter)-character-tokens that correspond to the 26 letters of the latin alphabet within two expansion steps. That routine does not require eTeX or the like extensions.

(!!!Be aware that having TeX read and tokenize input consisting of characters of the latin alphabet usually yields catcode-11(letter)-character tokens while expanding \string, \meaning, \jobmane and the like primitives delivers catcode-12(other)-character-tokens!!!)

As a (probably disliked) side effect that routine does replace pairs of matching catcode-1-character-tokens and catcode-2-character-tokens by pairs of matching curly catcode-1-brace-tokens and curly catcode-2-brace-tokens, i.e. { and }.

I think this should not be a problem with plain TeX and LaTeX2e as with these formats usually the only character with category code 1 is the opening curly brace { and the only character with category code 2 is the closing curly brace }.

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.