How can I avoid escaping the # character as a command argument in a Tikz environment?












2














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
ewcountendcsname scratchcounter
If you say, e.g., `defa1{...}', 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 newcountendcsname
...


Questions:




  • Can this be fixed in some way? How?

  • Or am I going the wrong way? Is there another path to achieve this goal?










share|improve this question


















  • 2




    off topic: you are defining mycommand inside definition of myenv?!
    – Sigur
    Dec 27 '18 at 17:03






  • 2




    off topic 2: do you know sharp?
    – Sigur
    Dec 27 '18 at 17:04










  • Q1: yes, because that command only makes sense inside the environment. Q2: no, thanks!
    – kebs
    Dec 27 '18 at 17:07












  • # 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










  • @DavidCarlisle The sharp command (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


















2














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
ewcountendcsname scratchcounter
If you say, e.g., `defa1{...}', 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 newcountendcsname
...


Questions:




  • Can this be fixed in some way? How?

  • Or am I going the wrong way? Is there another path to achieve this goal?










share|improve this question


















  • 2




    off topic: you are defining mycommand inside definition of myenv?!
    – Sigur
    Dec 27 '18 at 17:03






  • 2




    off topic 2: do you know sharp?
    – Sigur
    Dec 27 '18 at 17:04










  • Q1: yes, because that command only makes sense inside the environment. Q2: no, thanks!
    – kebs
    Dec 27 '18 at 17:07












  • # 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










  • @DavidCarlisle The sharp command (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
















2












2








2







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
ewcountendcsname scratchcounter
If you say, e.g., `defa1{...}', 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 newcountendcsname
...


Questions:




  • Can this be fixed in some way? How?

  • Or am I going the wrong way? Is there another path to achieve this goal?










share|improve this question













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
ewcountendcsname scratchcounter
If you say, e.g., `defa1{...}', 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 newcountendcsname
...


Questions:




  • Can this be fixed in some way? How?

  • Or am I going the wrong way? Is there another path to achieve this goal?







tikz-pgf characters






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 27 '18 at 17:00









kebskebs

493512




493512








  • 2




    off topic: you are defining mycommand inside definition of myenv?!
    – Sigur
    Dec 27 '18 at 17:03






  • 2




    off topic 2: do you know sharp?
    – Sigur
    Dec 27 '18 at 17:04










  • Q1: yes, because that command only makes sense inside the environment. Q2: no, thanks!
    – kebs
    Dec 27 '18 at 17:07












  • # 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










  • @DavidCarlisle The sharp command (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
















  • 2




    off topic: you are defining mycommand inside definition of myenv?!
    – Sigur
    Dec 27 '18 at 17:03






  • 2




    off topic 2: do you know sharp?
    – Sigur
    Dec 27 '18 at 17:04










  • Q1: yes, because that command only makes sense inside the environment. Q2: no, thanks!
    – kebs
    Dec 27 '18 at 17:07












  • # 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










  • @DavidCarlisle The sharp command (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










2




2




off topic: you are defining mycommand inside definition of myenv?!
– Sigur
Dec 27 '18 at 17:03




off topic: you are defining mycommand inside definition of myenv?!
– Sigur
Dec 27 '18 at 17:03




2




2




off topic 2: do you know sharp?
– Sigur
Dec 27 '18 at 17:04




off topic 2: do you know sharp?
– Sigur
Dec 27 '18 at 17:04












Q1: yes, because that command only makes sense inside the environment. Q2: no, thanks!
– kebs
Dec 27 '18 at 17:07






Q1: yes, because that command only makes sense inside the environment. Q2: no, thanks!
– kebs
Dec 27 '18 at 17:07














# 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




# 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












@DavidCarlisle The sharp command (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






@DavidCarlisle The sharp command (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












2 Answers
2






active

oldest

votes


















4














Delay the setting:



documentclass{article}
usepackage{tikz}

newenvironment{myenv}
{%
newcommand{mycommand}[1]
{%
draw(0,0) node {chord=##1};
}%
begin{tikzpicture}
}
{%
end{tikzpicture}%
}

AtBeginDocument{catcode`#=12 }

begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


It's a bad idea nonetheless. Use G# and your life will be better.






share|improve this answer





















  • Thanks for your answer! But about your last sentence, sure, I understand your point, the idea is just to avoid putting barriers in front of any potential new Latex users. No basic user should have to worry about those reserved characters (except maybe "%").The UI should be as simple as possible.
    – kebs
    Dec 27 '18 at 17:11












  • @kebs And potential errors as cryptical as possible…
    – TeXnician
    Dec 27 '18 at 17:17










  • @Texnician ;-) could be !
    – kebs
    Dec 27 '18 at 17:18












  • Thinking again about this: could you give some hints on why exactly this is a bad idea ? Maybe some example of a situation where this could break something ? Because the package user isn't expected to define new commands, where this trick could be an issue. But maybe I miss something?
    – kebs
    Dec 27 '18 at 17:32



















4














documentclass{article}
usepackage{tikz}

newcommand{mycommand}[1]
{
draw(0,0) node {chord=#1};
}

newenvironment{myenv}
{
catcode`#=12
begin{tikzpicture}
}
{
end{tikzpicture}
}



begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


enter image description here






share|improve this answer





















  • Thanks for answer. Was pretty much simple, indeed...
    – kebs
    Dec 27 '18 at 17:22










  • @kebs try for example fbox{begin{myenv}...end{myenv}} or any other command # won't work again, so you need (in principle) to document all the places where the syntax will or will not work instead of having a simple rule to say use # (or better sharp) everywhere.
    – David Carlisle
    Dec 27 '18 at 22:32










  • @DavidCarlisle Good point. But at present, the use case for the environment is pretty much straight forward, it just draws some lines, so there is no use case I see where a fbox would be needed. But... who knows ? I will consider it anyway, thanks.
    – kebs
    Dec 27 '18 at 23:00











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467562%2fhow-can-i-avoid-escaping-the-character-as-a-command-argument-in-a-tikz-environ%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Delay the setting:



documentclass{article}
usepackage{tikz}

newenvironment{myenv}
{%
newcommand{mycommand}[1]
{%
draw(0,0) node {chord=##1};
}%
begin{tikzpicture}
}
{%
end{tikzpicture}%
}

AtBeginDocument{catcode`#=12 }

begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


It's a bad idea nonetheless. Use G# and your life will be better.






share|improve this answer





















  • Thanks for your answer! But about your last sentence, sure, I understand your point, the idea is just to avoid putting barriers in front of any potential new Latex users. No basic user should have to worry about those reserved characters (except maybe "%").The UI should be as simple as possible.
    – kebs
    Dec 27 '18 at 17:11












  • @kebs And potential errors as cryptical as possible…
    – TeXnician
    Dec 27 '18 at 17:17










  • @Texnician ;-) could be !
    – kebs
    Dec 27 '18 at 17:18












  • Thinking again about this: could you give some hints on why exactly this is a bad idea ? Maybe some example of a situation where this could break something ? Because the package user isn't expected to define new commands, where this trick could be an issue. But maybe I miss something?
    – kebs
    Dec 27 '18 at 17:32
















4














Delay the setting:



documentclass{article}
usepackage{tikz}

newenvironment{myenv}
{%
newcommand{mycommand}[1]
{%
draw(0,0) node {chord=##1};
}%
begin{tikzpicture}
}
{%
end{tikzpicture}%
}

AtBeginDocument{catcode`#=12 }

begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


It's a bad idea nonetheless. Use G# and your life will be better.






share|improve this answer





















  • Thanks for your answer! But about your last sentence, sure, I understand your point, the idea is just to avoid putting barriers in front of any potential new Latex users. No basic user should have to worry about those reserved characters (except maybe "%").The UI should be as simple as possible.
    – kebs
    Dec 27 '18 at 17:11












  • @kebs And potential errors as cryptical as possible…
    – TeXnician
    Dec 27 '18 at 17:17










  • @Texnician ;-) could be !
    – kebs
    Dec 27 '18 at 17:18












  • Thinking again about this: could you give some hints on why exactly this is a bad idea ? Maybe some example of a situation where this could break something ? Because the package user isn't expected to define new commands, where this trick could be an issue. But maybe I miss something?
    – kebs
    Dec 27 '18 at 17:32














4












4








4






Delay the setting:



documentclass{article}
usepackage{tikz}

newenvironment{myenv}
{%
newcommand{mycommand}[1]
{%
draw(0,0) node {chord=##1};
}%
begin{tikzpicture}
}
{%
end{tikzpicture}%
}

AtBeginDocument{catcode`#=12 }

begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


It's a bad idea nonetheless. Use G# and your life will be better.






share|improve this answer












Delay the setting:



documentclass{article}
usepackage{tikz}

newenvironment{myenv}
{%
newcommand{mycommand}[1]
{%
draw(0,0) node {chord=##1};
}%
begin{tikzpicture}
}
{%
end{tikzpicture}%
}

AtBeginDocument{catcode`#=12 }

begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


It's a bad idea nonetheless. Use G# and your life will be better.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 27 '18 at 17:07









egregegreg

711k8618913174




711k8618913174












  • Thanks for your answer! But about your last sentence, sure, I understand your point, the idea is just to avoid putting barriers in front of any potential new Latex users. No basic user should have to worry about those reserved characters (except maybe "%").The UI should be as simple as possible.
    – kebs
    Dec 27 '18 at 17:11












  • @kebs And potential errors as cryptical as possible…
    – TeXnician
    Dec 27 '18 at 17:17










  • @Texnician ;-) could be !
    – kebs
    Dec 27 '18 at 17:18












  • Thinking again about this: could you give some hints on why exactly this is a bad idea ? Maybe some example of a situation where this could break something ? Because the package user isn't expected to define new commands, where this trick could be an issue. But maybe I miss something?
    – kebs
    Dec 27 '18 at 17:32


















  • Thanks for your answer! But about your last sentence, sure, I understand your point, the idea is just to avoid putting barriers in front of any potential new Latex users. No basic user should have to worry about those reserved characters (except maybe "%").The UI should be as simple as possible.
    – kebs
    Dec 27 '18 at 17:11












  • @kebs And potential errors as cryptical as possible…
    – TeXnician
    Dec 27 '18 at 17:17










  • @Texnician ;-) could be !
    – kebs
    Dec 27 '18 at 17:18












  • Thinking again about this: could you give some hints on why exactly this is a bad idea ? Maybe some example of a situation where this could break something ? Because the package user isn't expected to define new commands, where this trick could be an issue. But maybe I miss something?
    – kebs
    Dec 27 '18 at 17:32
















Thanks for your answer! But about your last sentence, sure, I understand your point, the idea is just to avoid putting barriers in front of any potential new Latex users. No basic user should have to worry about those reserved characters (except maybe "%").The UI should be as simple as possible.
– kebs
Dec 27 '18 at 17:11






Thanks for your answer! But about your last sentence, sure, I understand your point, the idea is just to avoid putting barriers in front of any potential new Latex users. No basic user should have to worry about those reserved characters (except maybe "%").The UI should be as simple as possible.
– kebs
Dec 27 '18 at 17:11














@kebs And potential errors as cryptical as possible…
– TeXnician
Dec 27 '18 at 17:17




@kebs And potential errors as cryptical as possible…
– TeXnician
Dec 27 '18 at 17:17












@Texnician ;-) could be !
– kebs
Dec 27 '18 at 17:18






@Texnician ;-) could be !
– kebs
Dec 27 '18 at 17:18














Thinking again about this: could you give some hints on why exactly this is a bad idea ? Maybe some example of a situation where this could break something ? Because the package user isn't expected to define new commands, where this trick could be an issue. But maybe I miss something?
– kebs
Dec 27 '18 at 17:32




Thinking again about this: could you give some hints on why exactly this is a bad idea ? Maybe some example of a situation where this could break something ? Because the package user isn't expected to define new commands, where this trick could be an issue. But maybe I miss something?
– kebs
Dec 27 '18 at 17:32











4














documentclass{article}
usepackage{tikz}

newcommand{mycommand}[1]
{
draw(0,0) node {chord=#1};
}

newenvironment{myenv}
{
catcode`#=12
begin{tikzpicture}
}
{
end{tikzpicture}
}



begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


enter image description here






share|improve this answer





















  • Thanks for answer. Was pretty much simple, indeed...
    – kebs
    Dec 27 '18 at 17:22










  • @kebs try for example fbox{begin{myenv}...end{myenv}} or any other command # won't work again, so you need (in principle) to document all the places where the syntax will or will not work instead of having a simple rule to say use # (or better sharp) everywhere.
    – David Carlisle
    Dec 27 '18 at 22:32










  • @DavidCarlisle Good point. But at present, the use case for the environment is pretty much straight forward, it just draws some lines, so there is no use case I see where a fbox would be needed. But... who knows ? I will consider it anyway, thanks.
    – kebs
    Dec 27 '18 at 23:00
















4














documentclass{article}
usepackage{tikz}

newcommand{mycommand}[1]
{
draw(0,0) node {chord=#1};
}

newenvironment{myenv}
{
catcode`#=12
begin{tikzpicture}
}
{
end{tikzpicture}
}



begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


enter image description here






share|improve this answer





















  • Thanks for answer. Was pretty much simple, indeed...
    – kebs
    Dec 27 '18 at 17:22










  • @kebs try for example fbox{begin{myenv}...end{myenv}} or any other command # won't work again, so you need (in principle) to document all the places where the syntax will or will not work instead of having a simple rule to say use # (or better sharp) everywhere.
    – David Carlisle
    Dec 27 '18 at 22:32










  • @DavidCarlisle Good point. But at present, the use case for the environment is pretty much straight forward, it just draws some lines, so there is no use case I see where a fbox would be needed. But... who knows ? I will consider it anyway, thanks.
    – kebs
    Dec 27 '18 at 23:00














4












4








4






documentclass{article}
usepackage{tikz}

newcommand{mycommand}[1]
{
draw(0,0) node {chord=#1};
}

newenvironment{myenv}
{
catcode`#=12
begin{tikzpicture}
}
{
end{tikzpicture}
}



begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


enter image description here






share|improve this answer












documentclass{article}
usepackage{tikz}

newcommand{mycommand}[1]
{
draw(0,0) node {chord=#1};
}

newenvironment{myenv}
{
catcode`#=12
begin{tikzpicture}
}
{
end{tikzpicture}
}



begin{document}
begin{myenv}
mycommand{G#}
end{myenv}
end{document}


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 27 '18 at 17:05









Ulrike FischerUlrike Fischer

188k7292673




188k7292673












  • Thanks for answer. Was pretty much simple, indeed...
    – kebs
    Dec 27 '18 at 17:22










  • @kebs try for example fbox{begin{myenv}...end{myenv}} or any other command # won't work again, so you need (in principle) to document all the places where the syntax will or will not work instead of having a simple rule to say use # (or better sharp) everywhere.
    – David Carlisle
    Dec 27 '18 at 22:32










  • @DavidCarlisle Good point. But at present, the use case for the environment is pretty much straight forward, it just draws some lines, so there is no use case I see where a fbox would be needed. But... who knows ? I will consider it anyway, thanks.
    – kebs
    Dec 27 '18 at 23:00


















  • Thanks for answer. Was pretty much simple, indeed...
    – kebs
    Dec 27 '18 at 17:22










  • @kebs try for example fbox{begin{myenv}...end{myenv}} or any other command # won't work again, so you need (in principle) to document all the places where the syntax will or will not work instead of having a simple rule to say use # (or better sharp) everywhere.
    – David Carlisle
    Dec 27 '18 at 22:32










  • @DavidCarlisle Good point. But at present, the use case for the environment is pretty much straight forward, it just draws some lines, so there is no use case I see where a fbox would be needed. But... who knows ? I will consider it anyway, thanks.
    – kebs
    Dec 27 '18 at 23:00
















Thanks for answer. Was pretty much simple, indeed...
– kebs
Dec 27 '18 at 17:22




Thanks for answer. Was pretty much simple, indeed...
– kebs
Dec 27 '18 at 17:22












@kebs try for example fbox{begin{myenv}...end{myenv}} or any other command # won't work again, so you need (in principle) to document all the places where the syntax will or will not work instead of having a simple rule to say use # (or better sharp) everywhere.
– David Carlisle
Dec 27 '18 at 22:32




@kebs try for example fbox{begin{myenv}...end{myenv}} or any other command # won't work again, so you need (in principle) to document all the places where the syntax will or will not work instead of having a simple rule to say use # (or better sharp) everywhere.
– David Carlisle
Dec 27 '18 at 22:32












@DavidCarlisle Good point. But at present, the use case for the environment is pretty much straight forward, it just draws some lines, so there is no use case I see where a fbox would be needed. But... who knows ? I will consider it anyway, thanks.
– kebs
Dec 27 '18 at 23:00




@DavidCarlisle Good point. But at present, the use case for the environment is pretty much straight forward, it just draws some lines, so there is no use case I see where a fbox would be needed. But... who knows ? I will consider it anyway, thanks.
– kebs
Dec 27 '18 at 23:00


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467562%2fhow-can-i-avoid-escaping-the-character-as-a-command-argument-in-a-tikz-environ%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Probability when a professor distributes a quiz and homework assignment to a class of n students.

Aardman Animations

Are they similar matrix