I am attempting to write a music related package where the user can enter chord names, that will be nicely printed:
% this prints out the C chord
\somecommand{C}
However, a chord names can have sharps and flats and I want the UI to be as simple as possible. Basically, avoid the need for the user to have to escape the # character, so he can write just this:
\somecommand{C#}
instead of this:
\somecommand{C\#}
In this answer, I read that this can be done with:
\catcode`#=12
So this, indeed, works:
\documentclass{article}
\newcommand{\mycommand}[1]
{
chord=#1
}
\catcode`#=12
\begin{document}
\mycommand{G#}
\end{document}
And prints "chord=G#".
However, I am unable to make that trick work in the real situation, because all of this is actually embedded into a Tikz environment:
\documentclass{article}
\usepackage{tikz}
\newenvironment{myenv}
{
\newcommand{\mycommand}[1]
{
\draw(0,0) node {chord=##1};
}
\begin{tikzpicture}
}
{
\end{tikzpicture}
}
\catcode`#=12
\begin{document}
\begin{myenv}
\mycommand{G#}
\end{myenv}
\end{document}
This MCVE produces lots of errors that I cannot understand:
ABD: EveryShipout initializing macros
(/usr/local/texlive/2017/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
! Use of \@@mptopdf@@newabove doesn't match its definition.
l.136 \@@mptopdf@@newabove \csname n
ewcount\endcsname \scratchcounter
If you say, e.g., `\def\a1{...}', then you must always
put `1' after `\a', since control sequence names are
made up of letters only. The macro here has not been
followed by the required stuff, so I'm ignoring it.
! Extra \endcsname.
l.136 ...opdf@@newabove \csname newcount\endcsname
...
Questions:
- Can this be fixed in some way? How?
- Or am I going the wrong way? Is there another path to achieve this goal?

\mycommandinside definition ofmyenv?! – Sigur Dec 27 '18 at 17:03\sharp? – Sigur Dec 27 '18 at 17:04\#is U+0023 (#, number sign) which isn't really the same character as \sharp U+266F (♯, Sharp) are you sure that you just want to allow an unquoted#to typeset as itself? – David Carlisle Dec 27 '18 at 22:23\sharpcommand (that I didn't know) looks indeed nicer but kinda too small, compared to the default rendering of\#(I mean in the readability sense, when seen from far away in a dark room). But I can consider these two options. – kebs Dec 28 '18 at 13:13