5

I am trying to setup my acronym list and I'm trying to use C# as an acronym but

\acro{C#}{Eine Programmiersprache von Microsoft}

Doesn't work since # is a reserved character so it gives the error

Illegal parameter number in definition of \reserved@a. \acro{C#}

So I tried to escape it as \#. This also doesn't work however:

\acro{C\#}{Eine Programmiersprache von Microsoft}

Missing \endcsname inserted. \acro{C\#}{Eine Programmiersprache von Microsoft}

I also googled Missing \endcsname which seems to be caused by an illegal character which has to be \ here.

I also saw some answers about catcode but it was encouraged not to use it if there is another solution.
Is there another solution?
Or should I rather use C Sharp in the acronym list? And if so, how do I still use C# in the text?

  • Before your comment I did not, however it doesn't seem to work either. It's underlined in red with the commend math command outside math env and if I try to compile it I get the same error (Missing \endcsname ...) as when I try \# – IDarkCoder Oct 23 '19 at 10:37
  • 3
    You can't put special symbols in the first argument (the "label"). I guess you should use something like \acro{Csharp}[C\#]{Eine Programmiersprache von Microsoft} and then use Csharp as label. – campa Oct 23 '19 at 10:42
  • @campa this works, thank you. To prevent that it uses the long text the first time I use the acronym I added \acused{C Sharp}. Mind posting that as an answer so I can accept it? – IDarkCoder Oct 23 '19 at 10:51
9

(Disclaimer: I'm absolutely sure there is a duplicate but I couldn't find it.)

From the acronym documentation:

In the acronym environment, acronyms are defined with the command:

\acro{<acronym>}[<short name>]{<full name>}.

The first argument <acronym> is the acronym string itself and is used in the commands of the previous section such as \ac or \acl, that print the different forms of the acronym. Because internal commands take <acronym> for storing the different forms of the acronym, the TEX code for the acronym is limited by \csname. If the acronym requires problematic or complicate TEX stuff (font commands, . . . ), then this code can be given in the optional argument <short name>. The first argument <acronym> is then a simpler string to identify the acronym. For example, an acronym for water can look like this:

\acro{H2O}[$\mathrm{H_2O}$]{water}

Then \acs{H2O} gets H2O and \acl{H2O} prints “water”.

The first argument of \acro is then like a label and as such should contain only characters allowed in \csname...\endcsname. The "complex" formatting (like, in this case, the sharp) can be passed as optional argument

\acro{Csharp}[C\#]{Eine Programmiersprache von Microsoft}

or

\acro{Csharp}[C$\sharp$]{Eine Programmiersprache von Microsoft}

For possible ways of typing the sharp please refer to How to make the correct hash-symbol in C Sharp (C#).

  • This Q/A is closely related, but is also specific to a particular character: How to escape ampersand in \acro command?. There seems to be a need for a more "generic" question. – barbara beeton Oct 23 '19 at 19:24
  • @barbarabeeton Thx. I see I've upvoted that, but it's not the dupe I mean. I could swear I've already copy/pasted the very same bit of the acronym doc for an answer, but I can't find it among mine. And there is not as many of them as in your case :-) Dunno, maybe it was only a draft I didn't post... – campa Oct 23 '19 at 20:03
  • Well, if you do find a good, general Q/A on this topic, please add it to the "often referenced questions" list in meta. – barbara beeton Oct 23 '19 at 20:44

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.