tikzcd doesnâÂÂt work in custom environment
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a document class test.cls
, in which I have defined a custom environment myenvironment
using the environ
package as follows:
NeedsTeXFormatLaTeX2e
ProvidesClasstest
LoadClassarticle
RequirePackagechangepage
RequirePackageenviron
NewEnvironmyenvironment
beginadjustwidth10pt10pt
BODY
endadjustwidth
Now if I try to use tikz-cd
inside myenvironment
, it fails, e.g. this gives an error:
beginmyenvironment
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
On the other hand, if I simply write it like thisâÂÂthat is, I substitute what the environment would doâÂÂ, everything is fine:
beginadjustwidth10pt10pt
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endadjustwidth
What could be the problem?
environments tikz-cd
add a comment |Â
up vote
1
down vote
favorite
I have a document class test.cls
, in which I have defined a custom environment myenvironment
using the environ
package as follows:
NeedsTeXFormatLaTeX2e
ProvidesClasstest
LoadClassarticle
RequirePackagechangepage
RequirePackageenviron
NewEnvironmyenvironment
beginadjustwidth10pt10pt
BODY
endadjustwidth
Now if I try to use tikz-cd
inside myenvironment
, it fails, e.g. this gives an error:
beginmyenvironment
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
On the other hand, if I simply write it like thisâÂÂthat is, I substitute what the environment would doâÂÂ, everything is fine:
beginadjustwidth10pt10pt
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endadjustwidth
What could be the problem?
environments tikz-cd
2
Why do you have to collect the contents ofmyenvironment
? Isn't LaTeX'snewenvironment
is enough here?
â Phelype Oleinik
50 mins ago
Indeed it is enough, I guess I just got too used to theenviron
package to notice. IâÂÂve tried it now and it solves the problem. I still wonder why it doesnâÂÂt work withenviron
though.
â Hermetically Sealed Halibut
45 mins ago
I posted an answer explaining why it doesn't work :)
â Phelype Oleinik
26 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a document class test.cls
, in which I have defined a custom environment myenvironment
using the environ
package as follows:
NeedsTeXFormatLaTeX2e
ProvidesClasstest
LoadClassarticle
RequirePackagechangepage
RequirePackageenviron
NewEnvironmyenvironment
beginadjustwidth10pt10pt
BODY
endadjustwidth
Now if I try to use tikz-cd
inside myenvironment
, it fails, e.g. this gives an error:
beginmyenvironment
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
On the other hand, if I simply write it like thisâÂÂthat is, I substitute what the environment would doâÂÂ, everything is fine:
beginadjustwidth10pt10pt
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endadjustwidth
What could be the problem?
environments tikz-cd
I have a document class test.cls
, in which I have defined a custom environment myenvironment
using the environ
package as follows:
NeedsTeXFormatLaTeX2e
ProvidesClasstest
LoadClassarticle
RequirePackagechangepage
RequirePackageenviron
NewEnvironmyenvironment
beginadjustwidth10pt10pt
BODY
endadjustwidth
Now if I try to use tikz-cd
inside myenvironment
, it fails, e.g. this gives an error:
beginmyenvironment
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
On the other hand, if I simply write it like thisâÂÂthat is, I substitute what the environment would doâÂÂ, everything is fine:
beginadjustwidth10pt10pt
[begintikzcd
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endadjustwidth
What could be the problem?
environments tikz-cd
environments tikz-cd
asked 52 mins ago
Hermetically Sealed Halibut
1086
1086
2
Why do you have to collect the contents ofmyenvironment
? Isn't LaTeX'snewenvironment
is enough here?
â Phelype Oleinik
50 mins ago
Indeed it is enough, I guess I just got too used to theenviron
package to notice. IâÂÂve tried it now and it solves the problem. I still wonder why it doesnâÂÂt work withenviron
though.
â Hermetically Sealed Halibut
45 mins ago
I posted an answer explaining why it doesn't work :)
â Phelype Oleinik
26 mins ago
add a comment |Â
2
Why do you have to collect the contents ofmyenvironment
? Isn't LaTeX'snewenvironment
is enough here?
â Phelype Oleinik
50 mins ago
Indeed it is enough, I guess I just got too used to theenviron
package to notice. IâÂÂve tried it now and it solves the problem. I still wonder why it doesnâÂÂt work withenviron
though.
â Hermetically Sealed Halibut
45 mins ago
I posted an answer explaining why it doesn't work :)
â Phelype Oleinik
26 mins ago
2
2
Why do you have to collect the contents of
myenvironment
? Isn't LaTeX's newenvironment
is enough here?â Phelype Oleinik
50 mins ago
Why do you have to collect the contents of
myenvironment
? Isn't LaTeX's newenvironment
is enough here?â Phelype Oleinik
50 mins ago
Indeed it is enough, I guess I just got too used to the
environ
package to notice. IâÂÂve tried it now and it solves the problem. I still wonder why it doesnâÂÂt work with environ
though.â Hermetically Sealed Halibut
45 mins ago
Indeed it is enough, I guess I just got too used to the
environ
package to notice. IâÂÂve tried it now and it solves the problem. I still wonder why it doesnâÂÂt work with environ
though.â Hermetically Sealed Halibut
45 mins ago
I posted an answer explaining why it doesn't work :)
â Phelype Oleinik
26 mins ago
I posted an answer explaining why it doesn't work :)
â Phelype Oleinik
26 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
You have to be very careful when collecting an environment with environ
, as this usually brings problems. When environ
collects its the environment it "freezes" the tokens of the environment. That is, everything will mean what it was when the outer environment was called. This will break every environment that somewhere redefines the category codes of any character (verbatim environments, for example), or that redefine some character.
In this particular case, the meaning of the &
changes when you enter tikzcd
. See:
documentclassarticle
usepackageamsmath
usepackagetikz-cd
begindocument
When textttenviron collects the environment:
ttfamilymeaning&
bigskip
What texttttikzcd expects texttt& to be:
begintikzcd
vbox to textwidthttfamilymeaning&
endtikzcd
enddocument
So basically, inside tikzcd
, &
means one thing, but when environ
reads it, it freezes the alignment tab character &
meaning, so it won't work.
So use environ
only when you are sure that you need it and you are sure that it won't break anything.
In your case you don't need environ
at all because you aren't applying any operation to the collected contents, so this:
newenvironmentmyenvironment
%
beginadjustwidth10pt10pt%
%
%
endadjustwidth
will suffice.
add a comment |Â
up vote
2
down vote
It doesn't work because myenvironment
absorbs the body of the environment as a macro argument; in these cases you have to pass ampersand replacement=&
to tikzcd
and use &
instead of &
, so
beginmyenvironment
[begintikzcd[ampersand replacement=&
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
However, there's no need for environ
here:
newenvironmentmyenvironment
beginadjustwidth10pt10pt
endadjustwidth
will do as well. And better, actually.
The cargo-cult version would be
newenvironmentmyenvironment
adjustwidth10pt10pt
endadjustwidth
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You have to be very careful when collecting an environment with environ
, as this usually brings problems. When environ
collects its the environment it "freezes" the tokens of the environment. That is, everything will mean what it was when the outer environment was called. This will break every environment that somewhere redefines the category codes of any character (verbatim environments, for example), or that redefine some character.
In this particular case, the meaning of the &
changes when you enter tikzcd
. See:
documentclassarticle
usepackageamsmath
usepackagetikz-cd
begindocument
When textttenviron collects the environment:
ttfamilymeaning&
bigskip
What texttttikzcd expects texttt& to be:
begintikzcd
vbox to textwidthttfamilymeaning&
endtikzcd
enddocument
So basically, inside tikzcd
, &
means one thing, but when environ
reads it, it freezes the alignment tab character &
meaning, so it won't work.
So use environ
only when you are sure that you need it and you are sure that it won't break anything.
In your case you don't need environ
at all because you aren't applying any operation to the collected contents, so this:
newenvironmentmyenvironment
%
beginadjustwidth10pt10pt%
%
%
endadjustwidth
will suffice.
add a comment |Â
up vote
2
down vote
accepted
You have to be very careful when collecting an environment with environ
, as this usually brings problems. When environ
collects its the environment it "freezes" the tokens of the environment. That is, everything will mean what it was when the outer environment was called. This will break every environment that somewhere redefines the category codes of any character (verbatim environments, for example), or that redefine some character.
In this particular case, the meaning of the &
changes when you enter tikzcd
. See:
documentclassarticle
usepackageamsmath
usepackagetikz-cd
begindocument
When textttenviron collects the environment:
ttfamilymeaning&
bigskip
What texttttikzcd expects texttt& to be:
begintikzcd
vbox to textwidthttfamilymeaning&
endtikzcd
enddocument
So basically, inside tikzcd
, &
means one thing, but when environ
reads it, it freezes the alignment tab character &
meaning, so it won't work.
So use environ
only when you are sure that you need it and you are sure that it won't break anything.
In your case you don't need environ
at all because you aren't applying any operation to the collected contents, so this:
newenvironmentmyenvironment
%
beginadjustwidth10pt10pt%
%
%
endadjustwidth
will suffice.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You have to be very careful when collecting an environment with environ
, as this usually brings problems. When environ
collects its the environment it "freezes" the tokens of the environment. That is, everything will mean what it was when the outer environment was called. This will break every environment that somewhere redefines the category codes of any character (verbatim environments, for example), or that redefine some character.
In this particular case, the meaning of the &
changes when you enter tikzcd
. See:
documentclassarticle
usepackageamsmath
usepackagetikz-cd
begindocument
When textttenviron collects the environment:
ttfamilymeaning&
bigskip
What texttttikzcd expects texttt& to be:
begintikzcd
vbox to textwidthttfamilymeaning&
endtikzcd
enddocument
So basically, inside tikzcd
, &
means one thing, but when environ
reads it, it freezes the alignment tab character &
meaning, so it won't work.
So use environ
only when you are sure that you need it and you are sure that it won't break anything.
In your case you don't need environ
at all because you aren't applying any operation to the collected contents, so this:
newenvironmentmyenvironment
%
beginadjustwidth10pt10pt%
%
%
endadjustwidth
will suffice.
You have to be very careful when collecting an environment with environ
, as this usually brings problems. When environ
collects its the environment it "freezes" the tokens of the environment. That is, everything will mean what it was when the outer environment was called. This will break every environment that somewhere redefines the category codes of any character (verbatim environments, for example), or that redefine some character.
In this particular case, the meaning of the &
changes when you enter tikzcd
. See:
documentclassarticle
usepackageamsmath
usepackagetikz-cd
begindocument
When textttenviron collects the environment:
ttfamilymeaning&
bigskip
What texttttikzcd expects texttt& to be:
begintikzcd
vbox to textwidthttfamilymeaning&
endtikzcd
enddocument
So basically, inside tikzcd
, &
means one thing, but when environ
reads it, it freezes the alignment tab character &
meaning, so it won't work.
So use environ
only when you are sure that you need it and you are sure that it won't break anything.
In your case you don't need environ
at all because you aren't applying any operation to the collected contents, so this:
newenvironmentmyenvironment
%
beginadjustwidth10pt10pt%
%
%
endadjustwidth
will suffice.
answered 27 mins ago
Phelype Oleinik
18.9k54173
18.9k54173
add a comment |Â
add a comment |Â
up vote
2
down vote
It doesn't work because myenvironment
absorbs the body of the environment as a macro argument; in these cases you have to pass ampersand replacement=&
to tikzcd
and use &
instead of &
, so
beginmyenvironment
[begintikzcd[ampersand replacement=&
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
However, there's no need for environ
here:
newenvironmentmyenvironment
beginadjustwidth10pt10pt
endadjustwidth
will do as well. And better, actually.
The cargo-cult version would be
newenvironmentmyenvironment
adjustwidth10pt10pt
endadjustwidth
add a comment |Â
up vote
2
down vote
It doesn't work because myenvironment
absorbs the body of the environment as a macro argument; in these cases you have to pass ampersand replacement=&
to tikzcd
and use &
instead of &
, so
beginmyenvironment
[begintikzcd[ampersand replacement=&
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
However, there's no need for environ
here:
newenvironmentmyenvironment
beginadjustwidth10pt10pt
endadjustwidth
will do as well. And better, actually.
The cargo-cult version would be
newenvironmentmyenvironment
adjustwidth10pt10pt
endadjustwidth
add a comment |Â
up vote
2
down vote
up vote
2
down vote
It doesn't work because myenvironment
absorbs the body of the environment as a macro argument; in these cases you have to pass ampersand replacement=&
to tikzcd
and use &
instead of &
, so
beginmyenvironment
[begintikzcd[ampersand replacement=&
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
However, there's no need for environ
here:
newenvironmentmyenvironment
beginadjustwidth10pt10pt
endadjustwidth
will do as well. And better, actually.
The cargo-cult version would be
newenvironmentmyenvironment
adjustwidth10pt10pt
endadjustwidth
It doesn't work because myenvironment
absorbs the body of the environment as a macro argument; in these cases you have to pass ampersand replacement=&
to tikzcd
and use &
instead of &
, so
beginmyenvironment
[begintikzcd[ampersand replacement=&
1 ar[r] ar[d] & 2 ar[d] \
3 ar[r] & 4 \
endtikzcd]
endmyenvironment
However, there's no need for environ
here:
newenvironmentmyenvironment
beginadjustwidth10pt10pt
endadjustwidth
will do as well. And better, actually.
The cargo-cult version would be
newenvironmentmyenvironment
adjustwidth10pt10pt
endadjustwidth
answered 28 mins ago
egreg
691k8518383087
691k8518383087
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f456291%2ftikzcd-doesn-t-work-in-custom-environment%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Why do you have to collect the contents of
myenvironment
? Isn't LaTeX'snewenvironment
is enough here?â Phelype Oleinik
50 mins ago
Indeed it is enough, I guess I just got too used to the
environ
package to notice. IâÂÂve tried it now and it solves the problem. I still wonder why it doesnâÂÂt work withenviron
though.â Hermetically Sealed Halibut
45 mins ago
I posted an answer explaining why it doesn't work :)
â Phelype Oleinik
26 mins ago