LyX | change macro argument order
up vote
2
down vote
favorite
In LyX, is it possible to change the order of required and option arguments of a macro?
I want to make the option argument come after the required argument in this macro.
If it's possible, how can I do it?
macros lyx arguments
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
up vote
2
down vote
favorite
In LyX, is it possible to change the order of required and option arguments of a macro?
I want to make the option argument come after the required argument in this macro.
If it's possible, how can I do it?
macros lyx arguments
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
It is possible in LaTeX of course. LyX is only a editor that hides (too much, in my opinion) of LaTeX
– Christian Hupfer
Apr 14 '17 at 15:40
1
I'm looking for a solution in LyX, if that's possible, to avoid writing code.
– Gal Grünfeld
Apr 15 '17 at 9:50
1
This way you learn nothing and will be a slave of TeX.SE ;-)
– Christian Hupfer
Apr 15 '17 at 9:51
1
Haha. I've no problem with writing code and learning relevant LaTeX/TeX code - I just want to automate as much as possible to decrease time needed to do things. And that's something that LyX is quite good at doing. Also, I want to have as least code as possible in my LyX document due to elegance (I render things automatically in LyX).
– Gal Grünfeld
Apr 15 '17 at 9:54
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
In LyX, is it possible to change the order of required and option arguments of a macro?
I want to make the option argument come after the required argument in this macro.
If it's possible, how can I do it?
macros lyx arguments
In LyX, is it possible to change the order of required and option arguments of a macro?
I want to make the option argument come after the required argument in this macro.
If it's possible, how can I do it?
macros lyx arguments
macros lyx arguments
asked Apr 14 '17 at 14:30
Gal Grünfeld
14813
14813
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
It is possible in LaTeX of course. LyX is only a editor that hides (too much, in my opinion) of LaTeX
– Christian Hupfer
Apr 14 '17 at 15:40
1
I'm looking for a solution in LyX, if that's possible, to avoid writing code.
– Gal Grünfeld
Apr 15 '17 at 9:50
1
This way you learn nothing and will be a slave of TeX.SE ;-)
– Christian Hupfer
Apr 15 '17 at 9:51
1
Haha. I've no problem with writing code and learning relevant LaTeX/TeX code - I just want to automate as much as possible to decrease time needed to do things. And that's something that LyX is quite good at doing. Also, I want to have as least code as possible in my LyX document due to elegance (I render things automatically in LyX).
– Gal Grünfeld
Apr 15 '17 at 9:54
add a comment |
It is possible in LaTeX of course. LyX is only a editor that hides (too much, in my opinion) of LaTeX
– Christian Hupfer
Apr 14 '17 at 15:40
1
I'm looking for a solution in LyX, if that's possible, to avoid writing code.
– Gal Grünfeld
Apr 15 '17 at 9:50
1
This way you learn nothing and will be a slave of TeX.SE ;-)
– Christian Hupfer
Apr 15 '17 at 9:51
1
Haha. I've no problem with writing code and learning relevant LaTeX/TeX code - I just want to automate as much as possible to decrease time needed to do things. And that's something that LyX is quite good at doing. Also, I want to have as least code as possible in my LyX document due to elegance (I render things automatically in LyX).
– Gal Grünfeld
Apr 15 '17 at 9:54
It is possible in LaTeX of course. LyX is only a editor that hides (too much, in my opinion) of LaTeX
– Christian Hupfer
Apr 14 '17 at 15:40
It is possible in LaTeX of course. LyX is only a editor that hides (too much, in my opinion) of LaTeX
– Christian Hupfer
Apr 14 '17 at 15:40
1
1
I'm looking for a solution in LyX, if that's possible, to avoid writing code.
– Gal Grünfeld
Apr 15 '17 at 9:50
I'm looking for a solution in LyX, if that's possible, to avoid writing code.
– Gal Grünfeld
Apr 15 '17 at 9:50
1
1
This way you learn nothing and will be a slave of TeX.SE ;-)
– Christian Hupfer
Apr 15 '17 at 9:51
This way you learn nothing and will be a slave of TeX.SE ;-)
– Christian Hupfer
Apr 15 '17 at 9:51
1
1
Haha. I've no problem with writing code and learning relevant LaTeX/TeX code - I just want to automate as much as possible to decrease time needed to do things. And that's something that LyX is quite good at doing. Also, I want to have as least code as possible in my LyX document due to elegance (I render things automatically in LyX).
– Gal Grünfeld
Apr 15 '17 at 9:54
Haha. I've no problem with writing code and learning relevant LaTeX/TeX code - I just want to automate as much as possible to decrease time needed to do things. And that's something that LyX is quite good at doing. Also, I want to have as least code as possible in my LyX document due to elegance (I render things automatically in LyX).
– Gal Grünfeld
Apr 15 '17 at 9:54
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I don't recommend doing this because it'll be confusing to anyone else who reads your document. It will also not work for all macros, particularly ones that play around with category codes prior to reading their arguments. That said it is possible.
Here's some LaTeX code that defines a macro flip
that will flip the required and optional arguments of a macro that's defined to have exactly one required argument and one optional argument.
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
For example, given the macro
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
you can write flipfoo
one time and it'll redefine foo
to take a required argument followed by an optional argument. Here's a complete document illustrating this.
documentclass{article}
usepackage{parskip}
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
begin{document}
Normal use:
foo{blah}
foo[option]{asdf}
Now we can flip the arguments:
flipfoo
foo{blah}
foo{asdf}[option]
end{document}
I've never used LyX before now, but I was able to insert my code into the preamble and achieve the same effect.
Note that flip
doesn't respect the lack of long
on a macro (i.e., macros defined via the def
family without long
or defined via newcommand*
). This is likely to lead to confusing errors in some cases. It's possible to deal with this similar to how etoolbox
patches macros, but it didn't seem worth it to do so for this answer.
It would also be possible to define flip
such that it didn't redefine its argument but instead such that flipfoo{required}[optional]
expanded to foo[optional]{required}
. Something like (untested)
longdefflip#1#2[#3]{#1[#3]{#2}}
which would turn the optional argument into a required one, but if you don't have the optional argument, there's no reason to use the flip
.
In conclusion, it's possible to do, but you probably shouldn't do it.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I don't recommend doing this because it'll be confusing to anyone else who reads your document. It will also not work for all macros, particularly ones that play around with category codes prior to reading their arguments. That said it is possible.
Here's some LaTeX code that defines a macro flip
that will flip the required and optional arguments of a macro that's defined to have exactly one required argument and one optional argument.
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
For example, given the macro
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
you can write flipfoo
one time and it'll redefine foo
to take a required argument followed by an optional argument. Here's a complete document illustrating this.
documentclass{article}
usepackage{parskip}
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
begin{document}
Normal use:
foo{blah}
foo[option]{asdf}
Now we can flip the arguments:
flipfoo
foo{blah}
foo{asdf}[option]
end{document}
I've never used LyX before now, but I was able to insert my code into the preamble and achieve the same effect.
Note that flip
doesn't respect the lack of long
on a macro (i.e., macros defined via the def
family without long
or defined via newcommand*
). This is likely to lead to confusing errors in some cases. It's possible to deal with this similar to how etoolbox
patches macros, but it didn't seem worth it to do so for this answer.
It would also be possible to define flip
such that it didn't redefine its argument but instead such that flipfoo{required}[optional]
expanded to foo[optional]{required}
. Something like (untested)
longdefflip#1#2[#3]{#1[#3]{#2}}
which would turn the optional argument into a required one, but if you don't have the optional argument, there's no reason to use the flip
.
In conclusion, it's possible to do, but you probably shouldn't do it.
add a comment |
up vote
0
down vote
I don't recommend doing this because it'll be confusing to anyone else who reads your document. It will also not work for all macros, particularly ones that play around with category codes prior to reading their arguments. That said it is possible.
Here's some LaTeX code that defines a macro flip
that will flip the required and optional arguments of a macro that's defined to have exactly one required argument and one optional argument.
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
For example, given the macro
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
you can write flipfoo
one time and it'll redefine foo
to take a required argument followed by an optional argument. Here's a complete document illustrating this.
documentclass{article}
usepackage{parskip}
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
begin{document}
Normal use:
foo{blah}
foo[option]{asdf}
Now we can flip the arguments:
flipfoo
foo{blah}
foo{asdf}[option]
end{document}
I've never used LyX before now, but I was able to insert my code into the preamble and achieve the same effect.
Note that flip
doesn't respect the lack of long
on a macro (i.e., macros defined via the def
family without long
or defined via newcommand*
). This is likely to lead to confusing errors in some cases. It's possible to deal with this similar to how etoolbox
patches macros, but it didn't seem worth it to do so for this answer.
It would also be possible to define flip
such that it didn't redefine its argument but instead such that flipfoo{required}[optional]
expanded to foo[optional]{required}
. Something like (untested)
longdefflip#1#2[#3]{#1[#3]{#2}}
which would turn the optional argument into a required one, but if you don't have the optional argument, there's no reason to use the flip
.
In conclusion, it's possible to do, but you probably shouldn't do it.
add a comment |
up vote
0
down vote
up vote
0
down vote
I don't recommend doing this because it'll be confusing to anyone else who reads your document. It will also not work for all macros, particularly ones that play around with category codes prior to reading their arguments. That said it is possible.
Here's some LaTeX code that defines a macro flip
that will flip the required and optional arguments of a macro that's defined to have exactly one required argument and one optional argument.
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
For example, given the macro
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
you can write flipfoo
one time and it'll redefine foo
to take a required argument followed by an optional argument. Here's a complete document illustrating this.
documentclass{article}
usepackage{parskip}
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
begin{document}
Normal use:
foo{blah}
foo[option]{asdf}
Now we can flip the arguments:
flipfoo
foo{blah}
foo{asdf}[option]
end{document}
I've never used LyX before now, but I was able to insert my code into the preamble and achieve the same effect.
Note that flip
doesn't respect the lack of long
on a macro (i.e., macros defined via the def
family without long
or defined via newcommand*
). This is likely to lead to confusing errors in some cases. It's possible to deal with this similar to how etoolbox
patches macros, but it didn't seem worth it to do so for this answer.
It would also be possible to define flip
such that it didn't redefine its argument but instead such that flipfoo{required}[optional]
expanded to foo[optional]{required}
. Something like (untested)
longdefflip#1#2[#3]{#1[#3]{#2}}
which would turn the optional argument into a required one, but if you don't have the optional argument, there's no reason to use the flip
.
In conclusion, it's possible to do, but you probably shouldn't do it.
I don't recommend doing this because it'll be confusing to anyone else who reads your document. It will also not work for all macros, particularly ones that play around with category codes prior to reading their arguments. That said it is possible.
Here's some LaTeX code that defines a macro flip
that will flip the required and optional arguments of a macro that's defined to have exactly one required argument and one optional argument.
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
For example, given the macro
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
you can write flipfoo
one time and it'll redefine foo
to take a required argument followed by an optional argument. Here's a complete document illustrating this.
documentclass{article}
usepackage{parskip}
usepackage{etoolbox}
makeatletter
newcommand*flip[1]{%
cslet{flip@string#1}#1%
longdef#1##1{%
@ifnextchar[{@flip{#1}{##1}}{csuse{flip@string#1}{##1}}%
}%
}
longdef@flip#1#2[#3]{%
csuse{flip@string#1}[#3]{#2}%
}
makeatother
newcommandfoo[2][none]{%
par
Required argument: #2\
Optional argument: #1%
}
begin{document}
Normal use:
foo{blah}
foo[option]{asdf}
Now we can flip the arguments:
flipfoo
foo{blah}
foo{asdf}[option]
end{document}
I've never used LyX before now, but I was able to insert my code into the preamble and achieve the same effect.
Note that flip
doesn't respect the lack of long
on a macro (i.e., macros defined via the def
family without long
or defined via newcommand*
). This is likely to lead to confusing errors in some cases. It's possible to deal with this similar to how etoolbox
patches macros, but it didn't seem worth it to do so for this answer.
It would also be possible to define flip
such that it didn't redefine its argument but instead such that flipfoo{required}[optional]
expanded to foo[optional]{required}
. Something like (untested)
longdefflip#1#2[#3]{#1[#3]{#2}}
which would turn the optional argument into a required one, but if you don't have the optional argument, there's no reason to use the flip
.
In conclusion, it's possible to do, but you probably shouldn't do it.
answered Jun 26 '17 at 16:21
TH.
46.9k10128195
46.9k10128195
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f364738%2flyx-change-macro-argument-order%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
It is possible in LaTeX of course. LyX is only a editor that hides (too much, in my opinion) of LaTeX
– Christian Hupfer
Apr 14 '17 at 15:40
1
I'm looking for a solution in LyX, if that's possible, to avoid writing code.
– Gal Grünfeld
Apr 15 '17 at 9:50
1
This way you learn nothing and will be a slave of TeX.SE ;-)
– Christian Hupfer
Apr 15 '17 at 9:51
1
Haha. I've no problem with writing code and learning relevant LaTeX/TeX code - I just want to automate as much as possible to decrease time needed to do things. And that's something that LyX is quite good at doing. Also, I want to have as least code as possible in my LyX document due to elegance (I render things automatically in LyX).
– Gal Grünfeld
Apr 15 '17 at 9:54