How to properly capture return value of a command?medskipamount, default value in article classStore a ratio value in command and then use it to recalculate a length?Save length with let commandHow to log the value of a variable?Trim size as fundamental TeX valuenew command not working properlyGet pseudo-length value in scrlttr2Can't properly calculate column widthStandalone build command does not capture all lengthHow to add an unit to a calculated value properly?
You look catfish vs You look like a catfish
Find the coordinate of two line segments that are perpendicular
When and why did journal article titles become descriptive, rather than creatively allusive?
Why was Germany not as successful as other Europeans in establishing overseas colonies?
What is a Recurrent Neural Network?
Feels like I am getting dragged in office politics
Electric guitar: why such heavy pots?
Pulling the rope with one hand is as heavy as with two hands?
gnu parallel how to use with ffmpeg
Pawn Sacrifice Justification
Upright [...] in italics quotation
Why do Ichisongas hate elephants and hippos?
Why is current rating for multicore cable lower than single core with the same cross section?
Does a creature that is immune to a condition still make a saving throw?
Why does nature favour the Laplacian?
Confused by notation of atomic number Z and mass number A on periodic table of elements
Is it possible to Ready a spell to be cast just before the start of your next turn by having the trigger be an ally's attack?
How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?
What does "rf" mean in "rfkill"?
Unexpected email from Yorkshire Bank
Illegal assignment from SObject to Contact
Can someone publish a story that happened to you?
How to creep the reader out with what seems like a normal person?
How to set the font color of quantity objects (Version 11.3 vs version 12)?
How to properly capture return value of a command?
medskipamount, default value in article classStore a ratio value in command and then use it to recalculate a length?Save length with let commandHow to log the value of a variable?Trim size as fundamental TeX valuenew command not working properlyGet pseudo-length value in scrlttr2Can't properly calculate column widthStandalone build command does not capture all lengthHow to add an unit to a calculated value properly?
I have a problem with capturing returned value of my command.
Here is my preamble with command definition:
documentclass[convert=density=300,size=800x600,outext=.png]standalone
usepackage[utf8]inputenc
usepackagetikz
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
% Function which returns maximum width needed to write any of provided arguments.
makeatletter
newlengthtextLength@getMaximumWidthHelper
newlengthtextLength@getMaximumWidth
newcommandgetMaximumWidthHelper[2]
%
settowidthtextLength@getMaximumWidthHelperpgfinterruptpicture #2endpgfinterruptpicture%
pgfmathparsemax(#1,textLength@getMaximumWidthHelper)%
@ifnextcharbgroupgetMaximumWidthHelperpgfmathresult ptpgfmathresult pt%
%
newcommandgetMaximumWidth[1]
%
settowidthtextLength@getMaximumWidthpgfinterruptpicture #1endpgfinterruptpicture%
@ifnextcharbgroupgetMaximumWidthHelperthetextLength@getMaximumWidththetextLength@getMaximumWidth%
%
makeatother
Working example used to test the above command:
begindocument
getMaximumWidthcmdOne
getMaximumWidthcmdOnecmdTwo
getMaximumWidthcmdOnecmdTwocmdThree
enddocument
However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.
begindocument
newlengthmaximumWidth
setlengthmaximumWidthgetMaximumWidthcmdOnecmdTwocmdThree
themaximumWidth
enddocument
On the second line, the return value of getMaximumWidth is not captured but instantly printed.
Afterwards I get an error:
! Missing number, treated as
zero.
After that, the third line just prints default value 0.0pt.
What is the proper way to capture the output of getMaximumWidth?
P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.
tikz-pgf lengths
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I have a problem with capturing returned value of my command.
Here is my preamble with command definition:
documentclass[convert=density=300,size=800x600,outext=.png]standalone
usepackage[utf8]inputenc
usepackagetikz
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
% Function which returns maximum width needed to write any of provided arguments.
makeatletter
newlengthtextLength@getMaximumWidthHelper
newlengthtextLength@getMaximumWidth
newcommandgetMaximumWidthHelper[2]
%
settowidthtextLength@getMaximumWidthHelperpgfinterruptpicture #2endpgfinterruptpicture%
pgfmathparsemax(#1,textLength@getMaximumWidthHelper)%
@ifnextcharbgroupgetMaximumWidthHelperpgfmathresult ptpgfmathresult pt%
%
newcommandgetMaximumWidth[1]
%
settowidthtextLength@getMaximumWidthpgfinterruptpicture #1endpgfinterruptpicture%
@ifnextcharbgroupgetMaximumWidthHelperthetextLength@getMaximumWidththetextLength@getMaximumWidth%
%
makeatother
Working example used to test the above command:
begindocument
getMaximumWidthcmdOne
getMaximumWidthcmdOnecmdTwo
getMaximumWidthcmdOnecmdTwocmdThree
enddocument
However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.
begindocument
newlengthmaximumWidth
setlengthmaximumWidthgetMaximumWidthcmdOnecmdTwocmdThree
themaximumWidth
enddocument
On the second line, the return value of getMaximumWidth is not captured but instantly printed.
Afterwards I get an error:
! Missing number, treated as
zero.
After that, the third line just prints default value 0.0pt.
What is the proper way to capture the output of getMaximumWidth?
P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.
tikz-pgf lengths
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
while@ifnextcharbgroupworks you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments usingdelimiters and a variable number of optional arguments which use[]delimiters. You have defined a command with optionalarguments which is wrong.
– David Carlisle
Apr 24 at 14:37
macros do not have return values, yourgetMaximumWidthexpands to a series of assignments so is not a length that can be used insetlength, you need to define it to leave a length in some command, saytempresultthen usegetMaximumWidthcmdOnecmdTwocmdThreesetlengthmaximumWidthtempresultor using a latex-conforming syntax,getMaximumWidthcmdOne,cmdTwo,cmdThreesetlengthmaximumWidthtempresult
– David Carlisle
Apr 24 at 15:43
That is exactly whypgfmathparseleaves its answer inpgfmathresult
– David Carlisle
Apr 24 at 15:45
Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.
– Iskustvo
Apr 24 at 16:00
add a comment |
I have a problem with capturing returned value of my command.
Here is my preamble with command definition:
documentclass[convert=density=300,size=800x600,outext=.png]standalone
usepackage[utf8]inputenc
usepackagetikz
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
% Function which returns maximum width needed to write any of provided arguments.
makeatletter
newlengthtextLength@getMaximumWidthHelper
newlengthtextLength@getMaximumWidth
newcommandgetMaximumWidthHelper[2]
%
settowidthtextLength@getMaximumWidthHelperpgfinterruptpicture #2endpgfinterruptpicture%
pgfmathparsemax(#1,textLength@getMaximumWidthHelper)%
@ifnextcharbgroupgetMaximumWidthHelperpgfmathresult ptpgfmathresult pt%
%
newcommandgetMaximumWidth[1]
%
settowidthtextLength@getMaximumWidthpgfinterruptpicture #1endpgfinterruptpicture%
@ifnextcharbgroupgetMaximumWidthHelperthetextLength@getMaximumWidththetextLength@getMaximumWidth%
%
makeatother
Working example used to test the above command:
begindocument
getMaximumWidthcmdOne
getMaximumWidthcmdOnecmdTwo
getMaximumWidthcmdOnecmdTwocmdThree
enddocument
However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.
begindocument
newlengthmaximumWidth
setlengthmaximumWidthgetMaximumWidthcmdOnecmdTwocmdThree
themaximumWidth
enddocument
On the second line, the return value of getMaximumWidth is not captured but instantly printed.
Afterwards I get an error:
! Missing number, treated as
zero.
After that, the third line just prints default value 0.0pt.
What is the proper way to capture the output of getMaximumWidth?
P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.
tikz-pgf lengths
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a problem with capturing returned value of my command.
Here is my preamble with command definition:
documentclass[convert=density=300,size=800x600,outext=.png]standalone
usepackage[utf8]inputenc
usepackagetikz
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
% Function which returns maximum width needed to write any of provided arguments.
makeatletter
newlengthtextLength@getMaximumWidthHelper
newlengthtextLength@getMaximumWidth
newcommandgetMaximumWidthHelper[2]
%
settowidthtextLength@getMaximumWidthHelperpgfinterruptpicture #2endpgfinterruptpicture%
pgfmathparsemax(#1,textLength@getMaximumWidthHelper)%
@ifnextcharbgroupgetMaximumWidthHelperpgfmathresult ptpgfmathresult pt%
%
newcommandgetMaximumWidth[1]
%
settowidthtextLength@getMaximumWidthpgfinterruptpicture #1endpgfinterruptpicture%
@ifnextcharbgroupgetMaximumWidthHelperthetextLength@getMaximumWidththetextLength@getMaximumWidth%
%
makeatother
Working example used to test the above command:
begindocument
getMaximumWidthcmdOne
getMaximumWidthcmdOnecmdTwo
getMaximumWidthcmdOnecmdTwocmdThree
enddocument
However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.
begindocument
newlengthmaximumWidth
setlengthmaximumWidthgetMaximumWidthcmdOnecmdTwocmdThree
themaximumWidth
enddocument
On the second line, the return value of getMaximumWidth is not captured but instantly printed.
Afterwards I get an error:
! Missing number, treated as
zero.
After that, the third line just prints default value 0.0pt.
What is the proper way to capture the output of getMaximumWidth?
P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.
tikz-pgf lengths
tikz-pgf lengths
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Apr 24 at 15:56
David Carlisle
502k4211491897
502k4211491897
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Apr 24 at 13:38
IskustvoIskustvo
1183
1183
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
while@ifnextcharbgroupworks you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments usingdelimiters and a variable number of optional arguments which use[]delimiters. You have defined a command with optionalarguments which is wrong.
– David Carlisle
Apr 24 at 14:37
macros do not have return values, yourgetMaximumWidthexpands to a series of assignments so is not a length that can be used insetlength, you need to define it to leave a length in some command, saytempresultthen usegetMaximumWidthcmdOnecmdTwocmdThreesetlengthmaximumWidthtempresultor using a latex-conforming syntax,getMaximumWidthcmdOne,cmdTwo,cmdThreesetlengthmaximumWidthtempresult
– David Carlisle
Apr 24 at 15:43
That is exactly whypgfmathparseleaves its answer inpgfmathresult
– David Carlisle
Apr 24 at 15:45
Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.
– Iskustvo
Apr 24 at 16:00
add a comment |
1
while@ifnextcharbgroupworks you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments usingdelimiters and a variable number of optional arguments which use[]delimiters. You have defined a command with optionalarguments which is wrong.
– David Carlisle
Apr 24 at 14:37
macros do not have return values, yourgetMaximumWidthexpands to a series of assignments so is not a length that can be used insetlength, you need to define it to leave a length in some command, saytempresultthen usegetMaximumWidthcmdOnecmdTwocmdThreesetlengthmaximumWidthtempresultor using a latex-conforming syntax,getMaximumWidthcmdOne,cmdTwo,cmdThreesetlengthmaximumWidthtempresult
– David Carlisle
Apr 24 at 15:43
That is exactly whypgfmathparseleaves its answer inpgfmathresult
– David Carlisle
Apr 24 at 15:45
Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.
– Iskustvo
Apr 24 at 16:00
1
1
while
@ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using delimiters and a variable number of optional arguments which use [] delimiters. You have defined a command with optional arguments which is wrong.– David Carlisle
Apr 24 at 14:37
while
@ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using delimiters and a variable number of optional arguments which use [] delimiters. You have defined a command with optional arguments which is wrong.– David Carlisle
Apr 24 at 14:37
macros do not have return values, your
getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidthcmdOnecmdTwocmdThreesetlengthmaximumWidthtempresult or using a latex-conforming syntax, getMaximumWidthcmdOne,cmdTwo,cmdThreesetlengthmaximumWidthtempresult– David Carlisle
Apr 24 at 15:43
macros do not have return values, your
getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidthcmdOnecmdTwocmdThreesetlengthmaximumWidthtempresult or using a latex-conforming syntax, getMaximumWidthcmdOne,cmdTwo,cmdThreesetlengthmaximumWidthtempresult– David Carlisle
Apr 24 at 15:43
That is exactly why
pgfmathparse leaves its answer in pgfmathresult– David Carlisle
Apr 24 at 15:45
That is exactly why
pgfmathparse leaves its answer in pgfmathresult– David Carlisle
Apr 24 at 15:45
Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.
– Iskustvo
Apr 24 at 16:00
Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.
– Iskustvo
Apr 24 at 16:00
add a comment |
2 Answers
2
active
oldest
votes
I'd generalize settowidth and, by the way, get also height and depth for free.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandsettomaximumwidthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settowidth #1 #2
NewDocumentCommandsettomaximumheightmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settoheight #1 #2
NewDocumentCommandsettomaximumdepthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settodepth #1 #2
dim_new:N l__iskustvo_tempa_dim
dim_new:N l__iskustvo_tempb_dim
tl_new:N l__iskustvo_temp_tl
cs_new_protected:Nn iskustvo_settomaxdim:Nnn
dim_zero:N l__iskustvo_tempa_dim
clist_map_variable:nNn #3 l__iskustvo_temp_tl
__iskustvo_measure:N #1
dim_set_eq:NN #2 l__iskustvo_tempa_dim
cs_new_protected:Nn __iskustvo_measure:N
#1l__iskustvo_tempb_diml__iskustvo_temp_tl
dim_set:Nn l__iskustvo_tempa_dim
dim_max:nn l__iskustvo_tempa_dim l__iskustvo_tempb_dim
ExplSyntaxOff
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
begindocument
newlengthtest
settomaximumwidthtestcmdOne,cmdTwo,cmdThree
thetest
settomaximumheighttestcmdOne,cmdTwo,cmdThree
thetest
settomaximumdepthtestcmdOne,cmdTwo,cmdThree
thetest
enddocument

2
Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.
– Iskustvo
Apr 24 at 17:22
I've read a bit and now that I understand what you did with this Elvish syntax, it's even more impressive! Luckily I think I'll just need the width, so I'll dumb it down a little.
– Iskustvo
Apr 25 at 19:30
add a comment |
I would write this something like

documentclassarticle
newcommandcmdFontfontsize1012selectfont% this is the default anyway
% Commands.
newcommandcmdOne cmdFont aaa
newcommandcmdTwo cmdFont bbbbb
newcommandcmdThreecmdFont cccc
newlengthmaximumWidth
newcommandgetMaximumWidth[1]%
settowidthmaximumWidthbegintabular@l@#1endtabular
begindocument
getMaximumWidthcmdOne\ cmdTwo\ cmdThree
themaximumWidth
enddocument
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
);
);
Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.
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%2f487375%2fhow-to-properly-capture-return-value-of-a-command%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
I'd generalize settowidth and, by the way, get also height and depth for free.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandsettomaximumwidthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settowidth #1 #2
NewDocumentCommandsettomaximumheightmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settoheight #1 #2
NewDocumentCommandsettomaximumdepthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settodepth #1 #2
dim_new:N l__iskustvo_tempa_dim
dim_new:N l__iskustvo_tempb_dim
tl_new:N l__iskustvo_temp_tl
cs_new_protected:Nn iskustvo_settomaxdim:Nnn
dim_zero:N l__iskustvo_tempa_dim
clist_map_variable:nNn #3 l__iskustvo_temp_tl
__iskustvo_measure:N #1
dim_set_eq:NN #2 l__iskustvo_tempa_dim
cs_new_protected:Nn __iskustvo_measure:N
#1l__iskustvo_tempb_diml__iskustvo_temp_tl
dim_set:Nn l__iskustvo_tempa_dim
dim_max:nn l__iskustvo_tempa_dim l__iskustvo_tempb_dim
ExplSyntaxOff
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
begindocument
newlengthtest
settomaximumwidthtestcmdOne,cmdTwo,cmdThree
thetest
settomaximumheighttestcmdOne,cmdTwo,cmdThree
thetest
settomaximumdepthtestcmdOne,cmdTwo,cmdThree
thetest
enddocument

2
Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.
– Iskustvo
Apr 24 at 17:22
I've read a bit and now that I understand what you did with this Elvish syntax, it's even more impressive! Luckily I think I'll just need the width, so I'll dumb it down a little.
– Iskustvo
Apr 25 at 19:30
add a comment |
I'd generalize settowidth and, by the way, get also height and depth for free.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandsettomaximumwidthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settowidth #1 #2
NewDocumentCommandsettomaximumheightmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settoheight #1 #2
NewDocumentCommandsettomaximumdepthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settodepth #1 #2
dim_new:N l__iskustvo_tempa_dim
dim_new:N l__iskustvo_tempb_dim
tl_new:N l__iskustvo_temp_tl
cs_new_protected:Nn iskustvo_settomaxdim:Nnn
dim_zero:N l__iskustvo_tempa_dim
clist_map_variable:nNn #3 l__iskustvo_temp_tl
__iskustvo_measure:N #1
dim_set_eq:NN #2 l__iskustvo_tempa_dim
cs_new_protected:Nn __iskustvo_measure:N
#1l__iskustvo_tempb_diml__iskustvo_temp_tl
dim_set:Nn l__iskustvo_tempa_dim
dim_max:nn l__iskustvo_tempa_dim l__iskustvo_tempb_dim
ExplSyntaxOff
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
begindocument
newlengthtest
settomaximumwidthtestcmdOne,cmdTwo,cmdThree
thetest
settomaximumheighttestcmdOne,cmdTwo,cmdThree
thetest
settomaximumdepthtestcmdOne,cmdTwo,cmdThree
thetest
enddocument

2
Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.
– Iskustvo
Apr 24 at 17:22
I've read a bit and now that I understand what you did with this Elvish syntax, it's even more impressive! Luckily I think I'll just need the width, so I'll dumb it down a little.
– Iskustvo
Apr 25 at 19:30
add a comment |
I'd generalize settowidth and, by the way, get also height and depth for free.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandsettomaximumwidthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settowidth #1 #2
NewDocumentCommandsettomaximumheightmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settoheight #1 #2
NewDocumentCommandsettomaximumdepthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settodepth #1 #2
dim_new:N l__iskustvo_tempa_dim
dim_new:N l__iskustvo_tempb_dim
tl_new:N l__iskustvo_temp_tl
cs_new_protected:Nn iskustvo_settomaxdim:Nnn
dim_zero:N l__iskustvo_tempa_dim
clist_map_variable:nNn #3 l__iskustvo_temp_tl
__iskustvo_measure:N #1
dim_set_eq:NN #2 l__iskustvo_tempa_dim
cs_new_protected:Nn __iskustvo_measure:N
#1l__iskustvo_tempb_diml__iskustvo_temp_tl
dim_set:Nn l__iskustvo_tempa_dim
dim_max:nn l__iskustvo_tempa_dim l__iskustvo_tempb_dim
ExplSyntaxOff
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
begindocument
newlengthtest
settomaximumwidthtestcmdOne,cmdTwo,cmdThree
thetest
settomaximumheighttestcmdOne,cmdTwo,cmdThree
thetest
settomaximumdepthtestcmdOne,cmdTwo,cmdThree
thetest
enddocument

I'd generalize settowidth and, by the way, get also height and depth for free.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandsettomaximumwidthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settowidth #1 #2
NewDocumentCommandsettomaximumheightmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settoheight #1 #2
NewDocumentCommandsettomaximumdepthmm
% #1 = length, #2 = comma separated list of objects
iskustvo_settomaxdim:Nnn settodepth #1 #2
dim_new:N l__iskustvo_tempa_dim
dim_new:N l__iskustvo_tempb_dim
tl_new:N l__iskustvo_temp_tl
cs_new_protected:Nn iskustvo_settomaxdim:Nnn
dim_zero:N l__iskustvo_tempa_dim
clist_map_variable:nNn #3 l__iskustvo_temp_tl
__iskustvo_measure:N #1
dim_set_eq:NN #2 l__iskustvo_tempa_dim
cs_new_protected:Nn __iskustvo_measure:N
#1l__iskustvo_tempb_diml__iskustvo_temp_tl
dim_set:Nn l__iskustvo_tempa_dim
dim_max:nn l__iskustvo_tempa_dim l__iskustvo_tempb_dim
ExplSyntaxOff
% Font used for writing commands.
defcmdFontfontsize1012selectfont
% Commands.
defcmdOne cmdFont aaa
defcmdTwo cmdFont bbbbb
defcmdThreecmdFont cccc
begindocument
newlengthtest
settomaximumwidthtestcmdOne,cmdTwo,cmdThree
thetest
settomaximumheighttestcmdOne,cmdTwo,cmdThree
thetest
settomaximumdepthtestcmdOne,cmdTwo,cmdThree
thetest
enddocument

answered Apr 24 at 17:04
egregegreg
737k8919393269
737k8919393269
2
Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.
– Iskustvo
Apr 24 at 17:22
I've read a bit and now that I understand what you did with this Elvish syntax, it's even more impressive! Luckily I think I'll just need the width, so I'll dumb it down a little.
– Iskustvo
Apr 25 at 19:30
add a comment |
2
Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.
– Iskustvo
Apr 24 at 17:22
I've read a bit and now that I understand what you did with this Elvish syntax, it's even more impressive! Luckily I think I'll just need the width, so I'll dumb it down a little.
– Iskustvo
Apr 25 at 19:30
2
2
Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.
– Iskustvo
Apr 24 at 17:22
Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.
– Iskustvo
Apr 24 at 17:22
I've read a bit and now that I understand what you did with this Elvish syntax, it's even more impressive! Luckily I think I'll just need the width, so I'll dumb it down a little.
– Iskustvo
Apr 25 at 19:30
I've read a bit and now that I understand what you did with this Elvish syntax, it's even more impressive! Luckily I think I'll just need the width, so I'll dumb it down a little.
– Iskustvo
Apr 25 at 19:30
add a comment |
I would write this something like

documentclassarticle
newcommandcmdFontfontsize1012selectfont% this is the default anyway
% Commands.
newcommandcmdOne cmdFont aaa
newcommandcmdTwo cmdFont bbbbb
newcommandcmdThreecmdFont cccc
newlengthmaximumWidth
newcommandgetMaximumWidth[1]%
settowidthmaximumWidthbegintabular@l@#1endtabular
begindocument
getMaximumWidthcmdOne\ cmdTwo\ cmdThree
themaximumWidth
enddocument
add a comment |
I would write this something like

documentclassarticle
newcommandcmdFontfontsize1012selectfont% this is the default anyway
% Commands.
newcommandcmdOne cmdFont aaa
newcommandcmdTwo cmdFont bbbbb
newcommandcmdThreecmdFont cccc
newlengthmaximumWidth
newcommandgetMaximumWidth[1]%
settowidthmaximumWidthbegintabular@l@#1endtabular
begindocument
getMaximumWidthcmdOne\ cmdTwo\ cmdThree
themaximumWidth
enddocument
add a comment |
I would write this something like

documentclassarticle
newcommandcmdFontfontsize1012selectfont% this is the default anyway
% Commands.
newcommandcmdOne cmdFont aaa
newcommandcmdTwo cmdFont bbbbb
newcommandcmdThreecmdFont cccc
newlengthmaximumWidth
newcommandgetMaximumWidth[1]%
settowidthmaximumWidthbegintabular@l@#1endtabular
begindocument
getMaximumWidthcmdOne\ cmdTwo\ cmdThree
themaximumWidth
enddocument
I would write this something like

documentclassarticle
newcommandcmdFontfontsize1012selectfont% this is the default anyway
% Commands.
newcommandcmdOne cmdFont aaa
newcommandcmdTwo cmdFont bbbbb
newcommandcmdThreecmdFont cccc
newlengthmaximumWidth
newcommandgetMaximumWidth[1]%
settowidthmaximumWidthbegintabular@l@#1endtabular
begindocument
getMaximumWidthcmdOne\ cmdTwo\ cmdThree
themaximumWidth
enddocument
answered Apr 24 at 15:54
David CarlisleDavid Carlisle
502k4211491897
502k4211491897
add a comment |
add a comment |
Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.
Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.
Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.
Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.
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%2f487375%2fhow-to-properly-capture-return-value-of-a-command%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
1
while
@ifnextcharbgroupworks you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments usingdelimiters and a variable number of optional arguments which use[]delimiters. You have defined a command with optionalarguments which is wrong.– David Carlisle
Apr 24 at 14:37
macros do not have return values, your
getMaximumWidthexpands to a series of assignments so is not a length that can be used insetlength, you need to define it to leave a length in some command, saytempresultthen usegetMaximumWidthcmdOnecmdTwocmdThreesetlengthmaximumWidthtempresultor using a latex-conforming syntax,getMaximumWidthcmdOne,cmdTwo,cmdThreesetlengthmaximumWidthtempresult– David Carlisle
Apr 24 at 15:43
That is exactly why
pgfmathparseleaves its answer inpgfmathresult– David Carlisle
Apr 24 at 15:45
Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.
– Iskustvo
Apr 24 at 16:00