xparse: Starred commands and IfBooleanTF












1















In some longer redefinition of existing code I am using a construct like



documentclass{book}
usepackage{xparse}


makeatletter
NewDocumentCommand{mymacro}{smO{}m}{
defblabla{#1}%
% several lines later in another macro I use
IfBooleanTF{blabla}{}{}
}

makeatother

begin{document}
mymacro*{}{}
end{document}


which works fine with texlive 2018 (xparse 2018-10-17) and lualatex.
However, when trying with texlive 2019 (xparse 2019-03-05), I get the following error



! Undefined control sequence.
<argument> LaTeX3 error:
Invalid use IfBooleanTF {blabla }
l.15 mymacro*{}{}


What would be the correct way of doing something like this with the new xparse version?





Here is my complete macro definition where the case above occurs: Basically, I am trying to remove the caption from subcaptions including the vertical space. To achieve this, I modified parts of the subcaption package. This works for TL2018 as mentioned above and yields the following output:



enter image description here



Please note that I was particularly looking for a minimal invasive solution with respect to the other code I have. To this end, I thought that just adding a * to the subcaptionbox is very convenient.



documentclass{book}

usepackage{xparse,graphicx,subcaption,mwe,float}

ExplSyntaxOn
DeclareExpandableDocumentCommand{IfNoValueOrEmptyTF}{mmm}
{
IfNoValueTF{#1}{#2}
{
tl_if_empty:nTF {#1} {#2} {#3}
}
}
ExplSyntaxOff
% This code makes subcaptionbox*{}{includegraphics...} print no label and remove the vertical space

makeatletter
letoldsubcaptionboxsubcaptionbox
RenewDocumentCommand{subcaptionbox}{smO{}m}{
defsubcaptionbox@skip@subcpation{#1}%
IfBooleanTF{#1}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox*{#2}{#4}%
}{%
oldsubcaptionbox*{#2}[#3]{#4}%
}%
}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox{#2}{#4}%
}{%
oldsubcaptionbox{#2}[#3]{#4}%
}%
}{%
}%
}

longdefcaption@iiibox#1#2#3#4[#5]#6{%
begingroup
#1*% set caption@position
caption@iftop{%
endgroup
parbox[t]{#4}{%
#1relax
caption@setposition t%
vbox{caption#2{#3}}%
captionbox@hrule
csname caption@hj@#5endcsname
#6}%
}{%
endgroup
parbox[b]{#4}{%
#1relax
caption@setposition b%
csname caption@hj@#5endcsname
#6%
captionbox@hrule%
IfBooleanTF{subcaptionbox@skip@subcpation}{%
IfNoValueOrEmptyTF{#3}{}{%
vtop{caption#2{#3}}%
}%
}{%
vtop{caption#2{#3}}%
}%
}%
}}
makeatother

begin{document}
begin{figure}[H]
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-b}}%
end{figure}
Blabla
begin{figure}[H]
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}
end{figure}
BlaBla
end{document}









share|improve this question

























  • Why were you saving the argument in a macro in the first place?

    – Joseph Wright
    Mar 28 at 23:08











  • @JosephWright I later redefine another macro where I use blabla. I did not know another way of doing something like this.

    – bonanza
    Mar 28 at 23:09






  • 1





    Please show us the complete macro(s) related to your issue. Make your code compilable and resulting in your issue, then we can copy it and test and play with on our computers to help you ...

    – Kurt
    Mar 29 at 0:58






  • 1





    The usage of IfNoValueOrEmptyTF doesn't make sense. If you use O{} there is no possibility for the -NoValue- flag, because it defaults to be empty. Also using expandafterIfBooleanTFexpandafter{subcaptionbox@skip@subcpation} should work (untested).

    – Skillmon
    Mar 29 at 10:30






  • 1





    @bonanza using o as argument specifier and then IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}} in the code should work, too.

    – Skillmon
    Mar 29 at 11:07
















1















In some longer redefinition of existing code I am using a construct like



documentclass{book}
usepackage{xparse}


makeatletter
NewDocumentCommand{mymacro}{smO{}m}{
defblabla{#1}%
% several lines later in another macro I use
IfBooleanTF{blabla}{}{}
}

makeatother

begin{document}
mymacro*{}{}
end{document}


which works fine with texlive 2018 (xparse 2018-10-17) and lualatex.
However, when trying with texlive 2019 (xparse 2019-03-05), I get the following error



! Undefined control sequence.
<argument> LaTeX3 error:
Invalid use IfBooleanTF {blabla }
l.15 mymacro*{}{}


What would be the correct way of doing something like this with the new xparse version?





Here is my complete macro definition where the case above occurs: Basically, I am trying to remove the caption from subcaptions including the vertical space. To achieve this, I modified parts of the subcaption package. This works for TL2018 as mentioned above and yields the following output:



enter image description here



Please note that I was particularly looking for a minimal invasive solution with respect to the other code I have. To this end, I thought that just adding a * to the subcaptionbox is very convenient.



documentclass{book}

usepackage{xparse,graphicx,subcaption,mwe,float}

ExplSyntaxOn
DeclareExpandableDocumentCommand{IfNoValueOrEmptyTF}{mmm}
{
IfNoValueTF{#1}{#2}
{
tl_if_empty:nTF {#1} {#2} {#3}
}
}
ExplSyntaxOff
% This code makes subcaptionbox*{}{includegraphics...} print no label and remove the vertical space

makeatletter
letoldsubcaptionboxsubcaptionbox
RenewDocumentCommand{subcaptionbox}{smO{}m}{
defsubcaptionbox@skip@subcpation{#1}%
IfBooleanTF{#1}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox*{#2}{#4}%
}{%
oldsubcaptionbox*{#2}[#3]{#4}%
}%
}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox{#2}{#4}%
}{%
oldsubcaptionbox{#2}[#3]{#4}%
}%
}{%
}%
}

longdefcaption@iiibox#1#2#3#4[#5]#6{%
begingroup
#1*% set caption@position
caption@iftop{%
endgroup
parbox[t]{#4}{%
#1relax
caption@setposition t%
vbox{caption#2{#3}}%
captionbox@hrule
csname caption@hj@#5endcsname
#6}%
}{%
endgroup
parbox[b]{#4}{%
#1relax
caption@setposition b%
csname caption@hj@#5endcsname
#6%
captionbox@hrule%
IfBooleanTF{subcaptionbox@skip@subcpation}{%
IfNoValueOrEmptyTF{#3}{}{%
vtop{caption#2{#3}}%
}%
}{%
vtop{caption#2{#3}}%
}%
}%
}}
makeatother

begin{document}
begin{figure}[H]
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-b}}%
end{figure}
Blabla
begin{figure}[H]
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}
end{figure}
BlaBla
end{document}









share|improve this question

























  • Why were you saving the argument in a macro in the first place?

    – Joseph Wright
    Mar 28 at 23:08











  • @JosephWright I later redefine another macro where I use blabla. I did not know another way of doing something like this.

    – bonanza
    Mar 28 at 23:09






  • 1





    Please show us the complete macro(s) related to your issue. Make your code compilable and resulting in your issue, then we can copy it and test and play with on our computers to help you ...

    – Kurt
    Mar 29 at 0:58






  • 1





    The usage of IfNoValueOrEmptyTF doesn't make sense. If you use O{} there is no possibility for the -NoValue- flag, because it defaults to be empty. Also using expandafterIfBooleanTFexpandafter{subcaptionbox@skip@subcpation} should work (untested).

    – Skillmon
    Mar 29 at 10:30






  • 1





    @bonanza using o as argument specifier and then IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}} in the code should work, too.

    – Skillmon
    Mar 29 at 11:07














1












1








1








In some longer redefinition of existing code I am using a construct like



documentclass{book}
usepackage{xparse}


makeatletter
NewDocumentCommand{mymacro}{smO{}m}{
defblabla{#1}%
% several lines later in another macro I use
IfBooleanTF{blabla}{}{}
}

makeatother

begin{document}
mymacro*{}{}
end{document}


which works fine with texlive 2018 (xparse 2018-10-17) and lualatex.
However, when trying with texlive 2019 (xparse 2019-03-05), I get the following error



! Undefined control sequence.
<argument> LaTeX3 error:
Invalid use IfBooleanTF {blabla }
l.15 mymacro*{}{}


What would be the correct way of doing something like this with the new xparse version?





Here is my complete macro definition where the case above occurs: Basically, I am trying to remove the caption from subcaptions including the vertical space. To achieve this, I modified parts of the subcaption package. This works for TL2018 as mentioned above and yields the following output:



enter image description here



Please note that I was particularly looking for a minimal invasive solution with respect to the other code I have. To this end, I thought that just adding a * to the subcaptionbox is very convenient.



documentclass{book}

usepackage{xparse,graphicx,subcaption,mwe,float}

ExplSyntaxOn
DeclareExpandableDocumentCommand{IfNoValueOrEmptyTF}{mmm}
{
IfNoValueTF{#1}{#2}
{
tl_if_empty:nTF {#1} {#2} {#3}
}
}
ExplSyntaxOff
% This code makes subcaptionbox*{}{includegraphics...} print no label and remove the vertical space

makeatletter
letoldsubcaptionboxsubcaptionbox
RenewDocumentCommand{subcaptionbox}{smO{}m}{
defsubcaptionbox@skip@subcpation{#1}%
IfBooleanTF{#1}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox*{#2}{#4}%
}{%
oldsubcaptionbox*{#2}[#3]{#4}%
}%
}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox{#2}{#4}%
}{%
oldsubcaptionbox{#2}[#3]{#4}%
}%
}{%
}%
}

longdefcaption@iiibox#1#2#3#4[#5]#6{%
begingroup
#1*% set caption@position
caption@iftop{%
endgroup
parbox[t]{#4}{%
#1relax
caption@setposition t%
vbox{caption#2{#3}}%
captionbox@hrule
csname caption@hj@#5endcsname
#6}%
}{%
endgroup
parbox[b]{#4}{%
#1relax
caption@setposition b%
csname caption@hj@#5endcsname
#6%
captionbox@hrule%
IfBooleanTF{subcaptionbox@skip@subcpation}{%
IfNoValueOrEmptyTF{#3}{}{%
vtop{caption#2{#3}}%
}%
}{%
vtop{caption#2{#3}}%
}%
}%
}}
makeatother

begin{document}
begin{figure}[H]
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-b}}%
end{figure}
Blabla
begin{figure}[H]
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}
end{figure}
BlaBla
end{document}









share|improve this question
















In some longer redefinition of existing code I am using a construct like



documentclass{book}
usepackage{xparse}


makeatletter
NewDocumentCommand{mymacro}{smO{}m}{
defblabla{#1}%
% several lines later in another macro I use
IfBooleanTF{blabla}{}{}
}

makeatother

begin{document}
mymacro*{}{}
end{document}


which works fine with texlive 2018 (xparse 2018-10-17) and lualatex.
However, when trying with texlive 2019 (xparse 2019-03-05), I get the following error



! Undefined control sequence.
<argument> LaTeX3 error:
Invalid use IfBooleanTF {blabla }
l.15 mymacro*{}{}


What would be the correct way of doing something like this with the new xparse version?





Here is my complete macro definition where the case above occurs: Basically, I am trying to remove the caption from subcaptions including the vertical space. To achieve this, I modified parts of the subcaption package. This works for TL2018 as mentioned above and yields the following output:



enter image description here



Please note that I was particularly looking for a minimal invasive solution with respect to the other code I have. To this end, I thought that just adding a * to the subcaptionbox is very convenient.



documentclass{book}

usepackage{xparse,graphicx,subcaption,mwe,float}

ExplSyntaxOn
DeclareExpandableDocumentCommand{IfNoValueOrEmptyTF}{mmm}
{
IfNoValueTF{#1}{#2}
{
tl_if_empty:nTF {#1} {#2} {#3}
}
}
ExplSyntaxOff
% This code makes subcaptionbox*{}{includegraphics...} print no label and remove the vertical space

makeatletter
letoldsubcaptionboxsubcaptionbox
RenewDocumentCommand{subcaptionbox}{smO{}m}{
defsubcaptionbox@skip@subcpation{#1}%
IfBooleanTF{#1}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox*{#2}{#4}%
}{%
oldsubcaptionbox*{#2}[#3]{#4}%
}%
}{%
IfNoValueOrEmptyTF{#3}{%
oldsubcaptionbox{#2}{#4}%
}{%
oldsubcaptionbox{#2}[#3]{#4}%
}%
}{%
}%
}

longdefcaption@iiibox#1#2#3#4[#5]#6{%
begingroup
#1*% set caption@position
caption@iftop{%
endgroup
parbox[t]{#4}{%
#1relax
caption@setposition t%
vbox{caption#2{#3}}%
captionbox@hrule
csname caption@hj@#5endcsname
#6}%
}{%
endgroup
parbox[b]{#4}{%
#1relax
caption@setposition b%
csname caption@hj@#5endcsname
#6%
captionbox@hrule%
IfBooleanTF{subcaptionbox@skip@subcpation}{%
IfNoValueOrEmptyTF{#3}{}{%
vtop{caption#2{#3}}%
}%
}{%
vtop{caption#2{#3}}%
}%
}%
}}
makeatother

begin{document}
begin{figure}[H]
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox{}{includegraphics[width=0.5linewidth]{example-image-b}}%
end{figure}
Blabla
begin{figure}[H]
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}
end{figure}
BlaBla
end{document}






xparse






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 29 at 8:47







bonanza

















asked Mar 28 at 23:03









bonanzabonanza

7541625




7541625













  • Why were you saving the argument in a macro in the first place?

    – Joseph Wright
    Mar 28 at 23:08











  • @JosephWright I later redefine another macro where I use blabla. I did not know another way of doing something like this.

    – bonanza
    Mar 28 at 23:09






  • 1





    Please show us the complete macro(s) related to your issue. Make your code compilable and resulting in your issue, then we can copy it and test and play with on our computers to help you ...

    – Kurt
    Mar 29 at 0:58






  • 1





    The usage of IfNoValueOrEmptyTF doesn't make sense. If you use O{} there is no possibility for the -NoValue- flag, because it defaults to be empty. Also using expandafterIfBooleanTFexpandafter{subcaptionbox@skip@subcpation} should work (untested).

    – Skillmon
    Mar 29 at 10:30






  • 1





    @bonanza using o as argument specifier and then IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}} in the code should work, too.

    – Skillmon
    Mar 29 at 11:07



















  • Why were you saving the argument in a macro in the first place?

    – Joseph Wright
    Mar 28 at 23:08











  • @JosephWright I later redefine another macro where I use blabla. I did not know another way of doing something like this.

    – bonanza
    Mar 28 at 23:09






  • 1





    Please show us the complete macro(s) related to your issue. Make your code compilable and resulting in your issue, then we can copy it and test and play with on our computers to help you ...

    – Kurt
    Mar 29 at 0:58






  • 1





    The usage of IfNoValueOrEmptyTF doesn't make sense. If you use O{} there is no possibility for the -NoValue- flag, because it defaults to be empty. Also using expandafterIfBooleanTFexpandafter{subcaptionbox@skip@subcpation} should work (untested).

    – Skillmon
    Mar 29 at 10:30






  • 1





    @bonanza using o as argument specifier and then IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}} in the code should work, too.

    – Skillmon
    Mar 29 at 11:07

















Why were you saving the argument in a macro in the first place?

– Joseph Wright
Mar 28 at 23:08





Why were you saving the argument in a macro in the first place?

– Joseph Wright
Mar 28 at 23:08













@JosephWright I later redefine another macro where I use blabla. I did not know another way of doing something like this.

– bonanza
Mar 28 at 23:09





@JosephWright I later redefine another macro where I use blabla. I did not know another way of doing something like this.

– bonanza
Mar 28 at 23:09




1




1





Please show us the complete macro(s) related to your issue. Make your code compilable and resulting in your issue, then we can copy it and test and play with on our computers to help you ...

– Kurt
Mar 29 at 0:58





Please show us the complete macro(s) related to your issue. Make your code compilable and resulting in your issue, then we can copy it and test and play with on our computers to help you ...

– Kurt
Mar 29 at 0:58




1




1





The usage of IfNoValueOrEmptyTF doesn't make sense. If you use O{} there is no possibility for the -NoValue- flag, because it defaults to be empty. Also using expandafterIfBooleanTFexpandafter{subcaptionbox@skip@subcpation} should work (untested).

– Skillmon
Mar 29 at 10:30





The usage of IfNoValueOrEmptyTF doesn't make sense. If you use O{} there is no possibility for the -NoValue- flag, because it defaults to be empty. Also using expandafterIfBooleanTFexpandafter{subcaptionbox@skip@subcpation} should work (untested).

– Skillmon
Mar 29 at 10:30




1




1





@bonanza using o as argument specifier and then IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}} in the code should work, too.

– Skillmon
Mar 29 at 11:07





@bonanza using o as argument specifier and then IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}} in the code should work, too.

– Skillmon
Mar 29 at 11:07










1 Answer
1






active

oldest

votes


















3














You're making your life difficult. If there is * and the argument is empty, just issue the last argument, possibly inside a box of the specified width.



documentclass{book}

usepackage{xparse,graphicx,subcaption}

letoldsubcaptionboxsubcaptionbox

ExplSyntaxOn
NewExpandableDocumentCommand{IfEmptyTF}{mmm}
{
tl_if_empty:nTF { #1 } { #2 } { #3 }
}
ExplSyntaxOff

RenewDocumentCommand{subcaptionbox}{smom}{%
IfBooleanTF{#1}
{%
IfEmptyTF{#2}
{#4}
{IfNoValueTF{#3}{oldsubcaptionbox*{#2}{#4}}{oldsubcaptionbox*{#2}[#3]{#4}}}%
}
{%
IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}}%
}%
}

begin{document}

begin{figure}[htp!]

subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

end{figure}

Blabla

begin{figure}[htp!]

subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

end{figure}

Blabla

begin{figure}[htp!]

subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}

end{figure}

BlaBla

end{document}


enter image description here






share|improve this answer
























    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%2f482003%2fxparse-starred-commands-and-ifbooleantf%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









    3














    You're making your life difficult. If there is * and the argument is empty, just issue the last argument, possibly inside a box of the specified width.



    documentclass{book}

    usepackage{xparse,graphicx,subcaption}

    letoldsubcaptionboxsubcaptionbox

    ExplSyntaxOn
    NewExpandableDocumentCommand{IfEmptyTF}{mmm}
    {
    tl_if_empty:nTF { #1 } { #2 } { #3 }
    }
    ExplSyntaxOff

    RenewDocumentCommand{subcaptionbox}{smom}{%
    IfBooleanTF{#1}
    {%
    IfEmptyTF{#2}
    {#4}
    {IfNoValueTF{#3}{oldsubcaptionbox*{#2}{#4}}{oldsubcaptionbox*{#2}[#3]{#4}}}%
    }
    {%
    IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}}%
    }%
    }

    begin{document}

    begin{figure}[htp!]

    subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
    subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

    end{figure}

    Blabla

    begin{figure}[htp!]

    subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
    subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

    end{figure}

    Blabla

    begin{figure}[htp!]

    subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
    subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}

    end{figure}

    BlaBla

    end{document}


    enter image description here






    share|improve this answer




























      3














      You're making your life difficult. If there is * and the argument is empty, just issue the last argument, possibly inside a box of the specified width.



      documentclass{book}

      usepackage{xparse,graphicx,subcaption}

      letoldsubcaptionboxsubcaptionbox

      ExplSyntaxOn
      NewExpandableDocumentCommand{IfEmptyTF}{mmm}
      {
      tl_if_empty:nTF { #1 } { #2 } { #3 }
      }
      ExplSyntaxOff

      RenewDocumentCommand{subcaptionbox}{smom}{%
      IfBooleanTF{#1}
      {%
      IfEmptyTF{#2}
      {#4}
      {IfNoValueTF{#3}{oldsubcaptionbox*{#2}{#4}}{oldsubcaptionbox*{#2}[#3]{#4}}}%
      }
      {%
      IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}}%
      }%
      }

      begin{document}

      begin{figure}[htp!]

      subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
      subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

      end{figure}

      Blabla

      begin{figure}[htp!]

      subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
      subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

      end{figure}

      Blabla

      begin{figure}[htp!]

      subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
      subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}

      end{figure}

      BlaBla

      end{document}


      enter image description here






      share|improve this answer


























        3












        3








        3







        You're making your life difficult. If there is * and the argument is empty, just issue the last argument, possibly inside a box of the specified width.



        documentclass{book}

        usepackage{xparse,graphicx,subcaption}

        letoldsubcaptionboxsubcaptionbox

        ExplSyntaxOn
        NewExpandableDocumentCommand{IfEmptyTF}{mmm}
        {
        tl_if_empty:nTF { #1 } { #2 } { #3 }
        }
        ExplSyntaxOff

        RenewDocumentCommand{subcaptionbox}{smom}{%
        IfBooleanTF{#1}
        {%
        IfEmptyTF{#2}
        {#4}
        {IfNoValueTF{#3}{oldsubcaptionbox*{#2}{#4}}{oldsubcaptionbox*{#2}[#3]{#4}}}%
        }
        {%
        IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}}%
        }%
        }

        begin{document}

        begin{figure}[htp!]

        subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
        subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

        end{figure}

        Blabla

        begin{figure}[htp!]

        subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
        subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

        end{figure}

        Blabla

        begin{figure}[htp!]

        subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
        subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}

        end{figure}

        BlaBla

        end{document}


        enter image description here






        share|improve this answer













        You're making your life difficult. If there is * and the argument is empty, just issue the last argument, possibly inside a box of the specified width.



        documentclass{book}

        usepackage{xparse,graphicx,subcaption}

        letoldsubcaptionboxsubcaptionbox

        ExplSyntaxOn
        NewExpandableDocumentCommand{IfEmptyTF}{mmm}
        {
        tl_if_empty:nTF { #1 } { #2 } { #3 }
        }
        ExplSyntaxOff

        RenewDocumentCommand{subcaptionbox}{smom}{%
        IfBooleanTF{#1}
        {%
        IfEmptyTF{#2}
        {#4}
        {IfNoValueTF{#3}{oldsubcaptionbox*{#2}{#4}}{oldsubcaptionbox*{#2}[#3]{#4}}}%
        }
        {%
        IfNoValueTF{#3}{oldsubcaptionbox{#2}{#4}}{oldsubcaptionbox{#2}[#3]{#4}}%
        }%
        }

        begin{document}

        begin{figure}[htp!]

        subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
        subcaptionbox{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

        end{figure}

        Blabla

        begin{figure}[htp!]

        subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-a}}%
        subcaptionbox*{zzz}{includegraphics[width=0.5linewidth]{example-image-b}}

        end{figure}

        Blabla

        begin{figure}[htp!]

        subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-a}}%
        subcaptionbox*{}{includegraphics[width=0.5linewidth]{example-image-b}}

        end{figure}

        BlaBla

        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 29 at 12:22









        egregegreg

        732k8919303253




        732k8919303253






























            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%2f482003%2fxparse-starred-commands-and-ifbooleantf%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

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?