Define command that accepts \ in argumentsHow to define a command that takes more than 9 argumentsEnumerate and itemize undefined + captions not workingDefining a newcommand for environment in CircuiTikzDefine command so that label works properlyA command to define other commands with argumentsHow to define a command that defines another command?How to define a command that takes more than 18 argumentshow to define newcommand that takes [] as arguments and not ?Can I define a macro that accepts everything until the next space?define variable with multiple arguments
OP Amp not amplifying audio signal
How to find if SQL server backup is encrypted with TDE without restoring the backup
What do you call someone who asks many questions?
how do we prove that a sum of two periods is still a period?
How can saying a song's name be a copyright violation?
Fair gambler's ruin problem intuition
Theorists sure want true answers to this!
What is the opposite of "eschatology"?
How do I exit BASH while loop using modulus operator?
Getting extremely large arrows with tikzcd
Is it possible to map the firing of neurons in the human brain so as to stimulate artificial memories in someone else?
Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)
Can a virus destroy the BIOS of a modern computer?
How do conventional missiles fly?
Processor speed limited at 0.4 Ghz
How exploitable/balanced is this homebrew spell: Spell Permanency?
What Exploit Are These User Agents Trying to Use?
Was the old ablative pronoun "med" or "mēd"?
What's the meaning of "Sollensaussagen"?
What exactly is ineptocracy?
How obscure is the use of 令 in 令和?
GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?
Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?
Using "tail" to follow a file without displaying the most recent lines
Define command that accepts \ in arguments
How to define a command that takes more than 9 argumentsEnumerate and itemize undefined + captions not workingDefining a newcommand for environment in CircuiTikzDefine command so that label works properlyA command to define other commands with argumentsHow to define a command that defines another command?How to define a command that takes more than 18 argumentshow to define newcommand that takes [] as arguments and not ?Can I define a macro that accepts everything until the next space?define variable with multiple arguments
I am trying to define a new command dfix
that can handle newlines in its arguments. The command works as expected when the arguments have no \
in them, but LaTeX produces errors if I do include newline characters.
How can I create a command/macro that is safe with regard to line breaks?
I would like dfix
in the following context
beginalign*
&dfix(A\
&B)C
endalign*
to produce the same output as
beginalign*
&(A\
&B)^ddag_C
endalign*
Similarly, $dfixAB$
should produce the same output as $A^ddag_B$
.
Here is a MWE defining the command and trying to us it in various places.
documentclassminimal
usepackageamsmath
newcommanddfix[2]ensuremath#1^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
macros errors align
|
show 1 more comment
I am trying to define a new command dfix
that can handle newlines in its arguments. The command works as expected when the arguments have no \
in them, but LaTeX produces errors if I do include newline characters.
How can I create a command/macro that is safe with regard to line breaks?
I would like dfix
in the following context
beginalign*
&dfix(A\
&B)C
endalign*
to produce the same output as
beginalign*
&(A\
&B)^ddag_C
endalign*
Similarly, $dfixAB$
should produce the same output as $A^ddag_B$
.
Here is a MWE defining the command and trying to us it in various places.
documentclassminimal
usepackageamsmath
newcommanddfix[2]ensuremath#1^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
macros errors align
So what do you expect when using your command with many lines?
– JouleV
2 days ago
you don't say what you expect the output to be. in that context the\
is ending the row of the align, but it is inside a group (it is the group that causes the error not the newcommand)
– David Carlisle
2 days ago
Easy way to enable multiline arguments:newcommanddfix[2]ensuremathbeginarray@c@#1endarray^ddag_#2
but that still wouldn't makedfixA\&BC
valid syntax. What do you wantdfix
to do?
– Skillmon
2 days ago
the macro has to expand to something that is valid in the align, so you can show the intended result by showing a workingalign
that does not usedfix
but makes the result you want. I can not guess from the code above,
– David Carlisle
2 days ago
I just edited the question to add an example showing the desired behaviour.
– Ryan Kavanagh
2 days ago
|
show 1 more comment
I am trying to define a new command dfix
that can handle newlines in its arguments. The command works as expected when the arguments have no \
in them, but LaTeX produces errors if I do include newline characters.
How can I create a command/macro that is safe with regard to line breaks?
I would like dfix
in the following context
beginalign*
&dfix(A\
&B)C
endalign*
to produce the same output as
beginalign*
&(A\
&B)^ddag_C
endalign*
Similarly, $dfixAB$
should produce the same output as $A^ddag_B$
.
Here is a MWE defining the command and trying to us it in various places.
documentclassminimal
usepackageamsmath
newcommanddfix[2]ensuremath#1^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
macros errors align
I am trying to define a new command dfix
that can handle newlines in its arguments. The command works as expected when the arguments have no \
in them, but LaTeX produces errors if I do include newline characters.
How can I create a command/macro that is safe with regard to line breaks?
I would like dfix
in the following context
beginalign*
&dfix(A\
&B)C
endalign*
to produce the same output as
beginalign*
&(A\
&B)^ddag_C
endalign*
Similarly, $dfixAB$
should produce the same output as $A^ddag_B$
.
Here is a MWE defining the command and trying to us it in various places.
documentclassminimal
usepackageamsmath
newcommanddfix[2]ensuremath#1^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
macros errors align
macros errors align
edited 2 days ago
David Carlisle
497k4111441891
497k4111441891
asked 2 days ago
Ryan KavanaghRyan Kavanagh
454
454
So what do you expect when using your command with many lines?
– JouleV
2 days ago
you don't say what you expect the output to be. in that context the\
is ending the row of the align, but it is inside a group (it is the group that causes the error not the newcommand)
– David Carlisle
2 days ago
Easy way to enable multiline arguments:newcommanddfix[2]ensuremathbeginarray@c@#1endarray^ddag_#2
but that still wouldn't makedfixA\&BC
valid syntax. What do you wantdfix
to do?
– Skillmon
2 days ago
the macro has to expand to something that is valid in the align, so you can show the intended result by showing a workingalign
that does not usedfix
but makes the result you want. I can not guess from the code above,
– David Carlisle
2 days ago
I just edited the question to add an example showing the desired behaviour.
– Ryan Kavanagh
2 days ago
|
show 1 more comment
So what do you expect when using your command with many lines?
– JouleV
2 days ago
you don't say what you expect the output to be. in that context the\
is ending the row of the align, but it is inside a group (it is the group that causes the error not the newcommand)
– David Carlisle
2 days ago
Easy way to enable multiline arguments:newcommanddfix[2]ensuremathbeginarray@c@#1endarray^ddag_#2
but that still wouldn't makedfixA\&BC
valid syntax. What do you wantdfix
to do?
– Skillmon
2 days ago
the macro has to expand to something that is valid in the align, so you can show the intended result by showing a workingalign
that does not usedfix
but makes the result you want. I can not guess from the code above,
– David Carlisle
2 days ago
I just edited the question to add an example showing the desired behaviour.
– Ryan Kavanagh
2 days ago
So what do you expect when using your command with many lines?
– JouleV
2 days ago
So what do you expect when using your command with many lines?
– JouleV
2 days ago
you don't say what you expect the output to be. in that context the
\
is ending the row of the align, but it is inside a group (it is the group that causes the error not the newcommand)– David Carlisle
2 days ago
you don't say what you expect the output to be. in that context the
\
is ending the row of the align, but it is inside a group (it is the group that causes the error not the newcommand)– David Carlisle
2 days ago
Easy way to enable multiline arguments:
newcommanddfix[2]ensuremathbeginarray@c@#1endarray^ddag_#2
but that still wouldn't make dfixA\&BC
valid syntax. What do you want dfix
to do?– Skillmon
2 days ago
Easy way to enable multiline arguments:
newcommanddfix[2]ensuremathbeginarray@c@#1endarray^ddag_#2
but that still wouldn't make dfixA\&BC
valid syntax. What do you want dfix
to do?– Skillmon
2 days ago
the macro has to expand to something that is valid in the align, so you can show the intended result by showing a working
align
that does not use dfix
but makes the result you want. I can not guess from the code above,– David Carlisle
2 days ago
the macro has to expand to something that is valid in the align, so you can show the intended result by showing a working
align
that does not use dfix
but makes the result you want. I can not guess from the code above,– David Carlisle
2 days ago
I just edited the question to add an example showing the desired behaviour.
– Ryan Kavanagh
2 days ago
I just edited the question to add an example showing the desired behaviour.
– Ryan Kavanagh
2 days ago
|
show 1 more comment
1 Answer
1
active
oldest
votes
This does what you ask but seems a very weird construct, are you sure this is what you need?
documentclassminimal
usepackageamsmath
newcommanddfix[2](#1)^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing } inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
Thanks David! The parentheses are not needed inside the body ofdfix
. The intention is that$dfixfX$
describes an operation on a functions f. When the first argument is a single letter, then no parentheses are needed (i.e., the output should be$f^ddag_X$
), but I was encountering issues when I had to split long function expression across several lines, e.g.,$dfix(A\B)X$
. Getting rid of the braces around#1
as you did and changing the definition tonewcommanddfix[2]#1^ddag_#2
seems to have fixed my problem.
– Ryan Kavanagh
2 days ago
@RyanKavanagh OK I would never use that markup personally, having a macro argument start in one alignment cell and end in another is extremely weird, but as I show it's not technically invalid so if it does what you want, that's OK:-)
– David Carlisle
2 days ago
add a comment |
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
);
);
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%2f482453%2fdefine-command-that-accepts-in-arguments%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This does what you ask but seems a very weird construct, are you sure this is what you need?
documentclassminimal
usepackageamsmath
newcommanddfix[2](#1)^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing } inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
Thanks David! The parentheses are not needed inside the body ofdfix
. The intention is that$dfixfX$
describes an operation on a functions f. When the first argument is a single letter, then no parentheses are needed (i.e., the output should be$f^ddag_X$
), but I was encountering issues when I had to split long function expression across several lines, e.g.,$dfix(A\B)X$
. Getting rid of the braces around#1
as you did and changing the definition tonewcommanddfix[2]#1^ddag_#2
seems to have fixed my problem.
– Ryan Kavanagh
2 days ago
@RyanKavanagh OK I would never use that markup personally, having a macro argument start in one alignment cell and end in another is extremely weird, but as I show it's not technically invalid so if it does what you want, that's OK:-)
– David Carlisle
2 days ago
add a comment |
This does what you ask but seems a very weird construct, are you sure this is what you need?
documentclassminimal
usepackageamsmath
newcommanddfix[2](#1)^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing } inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
Thanks David! The parentheses are not needed inside the body ofdfix
. The intention is that$dfixfX$
describes an operation on a functions f. When the first argument is a single letter, then no parentheses are needed (i.e., the output should be$f^ddag_X$
), but I was encountering issues when I had to split long function expression across several lines, e.g.,$dfix(A\B)X$
. Getting rid of the braces around#1
as you did and changing the definition tonewcommanddfix[2]#1^ddag_#2
seems to have fixed my problem.
– Ryan Kavanagh
2 days ago
@RyanKavanagh OK I would never use that markup personally, having a macro argument start in one alignment cell and end in another is extremely weird, but as I show it's not technically invalid so if it does what you want, that's OK:-)
– David Carlisle
2 days ago
add a comment |
This does what you ask but seems a very weird construct, are you sure this is what you need?
documentclassminimal
usepackageamsmath
newcommanddfix[2](#1)^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing } inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
This does what you ask but seems a very weird construct, are you sure this is what you need?
documentclassminimal
usepackageamsmath
newcommanddfix[2](#1)^ddag_#2
begindocument
% This causes: ./mwe.tex:9: Missing } inserted.
beginalign*
&dfixA\
&BC
endalign*
% This is OK
beginalign*
&dfixA BC
endalign*
% This also produces errors.
beginmultline*
dfixA\
BC
endmultline*
enddocument
answered 2 days ago
David CarlisleDavid Carlisle
497k4111441891
497k4111441891
Thanks David! The parentheses are not needed inside the body ofdfix
. The intention is that$dfixfX$
describes an operation on a functions f. When the first argument is a single letter, then no parentheses are needed (i.e., the output should be$f^ddag_X$
), but I was encountering issues when I had to split long function expression across several lines, e.g.,$dfix(A\B)X$
. Getting rid of the braces around#1
as you did and changing the definition tonewcommanddfix[2]#1^ddag_#2
seems to have fixed my problem.
– Ryan Kavanagh
2 days ago
@RyanKavanagh OK I would never use that markup personally, having a macro argument start in one alignment cell and end in another is extremely weird, but as I show it's not technically invalid so if it does what you want, that's OK:-)
– David Carlisle
2 days ago
add a comment |
Thanks David! The parentheses are not needed inside the body ofdfix
. The intention is that$dfixfX$
describes an operation on a functions f. When the first argument is a single letter, then no parentheses are needed (i.e., the output should be$f^ddag_X$
), but I was encountering issues when I had to split long function expression across several lines, e.g.,$dfix(A\B)X$
. Getting rid of the braces around#1
as you did and changing the definition tonewcommanddfix[2]#1^ddag_#2
seems to have fixed my problem.
– Ryan Kavanagh
2 days ago
@RyanKavanagh OK I would never use that markup personally, having a macro argument start in one alignment cell and end in another is extremely weird, but as I show it's not technically invalid so if it does what you want, that's OK:-)
– David Carlisle
2 days ago
Thanks David! The parentheses are not needed inside the body of
dfix
. The intention is that $dfixfX$
describes an operation on a functions f. When the first argument is a single letter, then no parentheses are needed (i.e., the output should be $f^ddag_X$
), but I was encountering issues when I had to split long function expression across several lines, e.g., $dfix(A\B)X$
. Getting rid of the braces around #1
as you did and changing the definition to newcommanddfix[2]#1^ddag_#2
seems to have fixed my problem.– Ryan Kavanagh
2 days ago
Thanks David! The parentheses are not needed inside the body of
dfix
. The intention is that $dfixfX$
describes an operation on a functions f. When the first argument is a single letter, then no parentheses are needed (i.e., the output should be $f^ddag_X$
), but I was encountering issues when I had to split long function expression across several lines, e.g., $dfix(A\B)X$
. Getting rid of the braces around #1
as you did and changing the definition to newcommanddfix[2]#1^ddag_#2
seems to have fixed my problem.– Ryan Kavanagh
2 days ago
@RyanKavanagh OK I would never use that markup personally, having a macro argument start in one alignment cell and end in another is extremely weird, but as I show it's not technically invalid so if it does what you want, that's OK:-)
– David Carlisle
2 days ago
@RyanKavanagh OK I would never use that markup personally, having a macro argument start in one alignment cell and end in another is extremely weird, but as I show it's not technically invalid so if it does what you want, that's OK:-)
– David Carlisle
2 days ago
add a comment |
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.
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%2f482453%2fdefine-command-that-accepts-in-arguments%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
So what do you expect when using your command with many lines?
– JouleV
2 days ago
you don't say what you expect the output to be. in that context the
\
is ending the row of the align, but it is inside a group (it is the group that causes the error not the newcommand)– David Carlisle
2 days ago
Easy way to enable multiline arguments:
newcommanddfix[2]ensuremathbeginarray@c@#1endarray^ddag_#2
but that still wouldn't makedfixA\&BC
valid syntax. What do you wantdfix
to do?– Skillmon
2 days ago
the macro has to expand to something that is valid in the align, so you can show the intended result by showing a working
align
that does not usedfix
but makes the result you want. I can not guess from the code above,– David Carlisle
2 days ago
I just edited the question to add an example showing the desired behaviour.
– Ryan Kavanagh
2 days ago