Problem with nested if statements

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I'm trying to use some nested if statements to decide if a file exists and what kind of loadings are possible:



IfFileExists./emoji.sty
ifxetex
usepackage[bw,font=seguiemj.ttf]emoji
usepackagefontspec
else
usepackageifluatex
ifluatex
usepackage[bw,font=Symbola_hint.ttf]emoji
usepackagefontspec
else
usepackage[bw]emoji
fi
fi
newcommanddoxygenemoji[3]
IfFileExistsbw/#3.png
emoji#3

#1



renewcommanddoxygenemoji[3] #1



but unfortunately I get the error message:



! Extra else.
IfFileExists ...ileonpath #1#2#3}fi else
closein @inputcheck ede...
l.60 }


where line 60 is the last closing bracket (}).



(Not yet a real MWE but hopefully I can get some hints already).










share|improve this question



















  • 1




    Load ifluatex before starting IfFileExists; otherwise ifluatex is not a conditional unless you are using luatex and therefore a missing conditional error ensues.
    – egreg
    1 hour ago










  • @egreg, but one still needs the double ##, correct?
    – albert
    1 hour ago










  • Yes, I was explaining the “apparently doesn't like the ifluatex conditional“ in Phelype's answer. By the way, you have several spurious spaces in your code.
    – egreg
    1 hour ago











  • the ones with the renewcommand (should be newcommand) around the #1 are known. Which others?
    – albert
    1 hour ago











  • @egreg Ooh, that explains the problem with the conditional. Same problem as in my question about docstrip a few weeks ago. I'm a slow learner :P
    – Phelype Oleinik
    1 hour ago














up vote
2
down vote

favorite












I'm trying to use some nested if statements to decide if a file exists and what kind of loadings are possible:



IfFileExists./emoji.sty
ifxetex
usepackage[bw,font=seguiemj.ttf]emoji
usepackagefontspec
else
usepackageifluatex
ifluatex
usepackage[bw,font=Symbola_hint.ttf]emoji
usepackagefontspec
else
usepackage[bw]emoji
fi
fi
newcommanddoxygenemoji[3]
IfFileExistsbw/#3.png
emoji#3

#1



renewcommanddoxygenemoji[3] #1



but unfortunately I get the error message:



! Extra else.
IfFileExists ...ileonpath #1#2#3}fi else
closein @inputcheck ede...
l.60 }


where line 60 is the last closing bracket (}).



(Not yet a real MWE but hopefully I can get some hints already).










share|improve this question



















  • 1




    Load ifluatex before starting IfFileExists; otherwise ifluatex is not a conditional unless you are using luatex and therefore a missing conditional error ensues.
    – egreg
    1 hour ago










  • @egreg, but one still needs the double ##, correct?
    – albert
    1 hour ago










  • Yes, I was explaining the “apparently doesn't like the ifluatex conditional“ in Phelype's answer. By the way, you have several spurious spaces in your code.
    – egreg
    1 hour ago











  • the ones with the renewcommand (should be newcommand) around the #1 are known. Which others?
    – albert
    1 hour ago











  • @egreg Ooh, that explains the problem with the conditional. Same problem as in my question about docstrip a few weeks ago. I'm a slow learner :P
    – Phelype Oleinik
    1 hour ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to use some nested if statements to decide if a file exists and what kind of loadings are possible:



IfFileExists./emoji.sty
ifxetex
usepackage[bw,font=seguiemj.ttf]emoji
usepackagefontspec
else
usepackageifluatex
ifluatex
usepackage[bw,font=Symbola_hint.ttf]emoji
usepackagefontspec
else
usepackage[bw]emoji
fi
fi
newcommanddoxygenemoji[3]
IfFileExistsbw/#3.png
emoji#3

#1



renewcommanddoxygenemoji[3] #1



but unfortunately I get the error message:



! Extra else.
IfFileExists ...ileonpath #1#2#3}fi else
closein @inputcheck ede...
l.60 }


where line 60 is the last closing bracket (}).



(Not yet a real MWE but hopefully I can get some hints already).










share|improve this question















I'm trying to use some nested if statements to decide if a file exists and what kind of loadings are possible:



IfFileExists./emoji.sty
ifxetex
usepackage[bw,font=seguiemj.ttf]emoji
usepackagefontspec
else
usepackageifluatex
ifluatex
usepackage[bw,font=Symbola_hint.ttf]emoji
usepackagefontspec
else
usepackage[bw]emoji
fi
fi
newcommanddoxygenemoji[3]
IfFileExistsbw/#3.png
emoji#3

#1



renewcommanddoxygenemoji[3] #1



but unfortunately I get the error message:



! Extra else.
IfFileExists ...ileonpath #1#2#3}fi else
closein @inputcheck ede...
l.60 }


where line 60 is the last closing bracket (}).



(Not yet a real MWE but hopefully I can get some hints already).







conditionals nesting ifthenelse






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Phelype Oleinik

17.3k43770




17.3k43770










asked 2 hours ago









albert

450314




450314







  • 1




    Load ifluatex before starting IfFileExists; otherwise ifluatex is not a conditional unless you are using luatex and therefore a missing conditional error ensues.
    – egreg
    1 hour ago










  • @egreg, but one still needs the double ##, correct?
    – albert
    1 hour ago










  • Yes, I was explaining the “apparently doesn't like the ifluatex conditional“ in Phelype's answer. By the way, you have several spurious spaces in your code.
    – egreg
    1 hour ago











  • the ones with the renewcommand (should be newcommand) around the #1 are known. Which others?
    – albert
    1 hour ago











  • @egreg Ooh, that explains the problem with the conditional. Same problem as in my question about docstrip a few weeks ago. I'm a slow learner :P
    – Phelype Oleinik
    1 hour ago












  • 1




    Load ifluatex before starting IfFileExists; otherwise ifluatex is not a conditional unless you are using luatex and therefore a missing conditional error ensues.
    – egreg
    1 hour ago










  • @egreg, but one still needs the double ##, correct?
    – albert
    1 hour ago










  • Yes, I was explaining the “apparently doesn't like the ifluatex conditional“ in Phelype's answer. By the way, you have several spurious spaces in your code.
    – egreg
    1 hour ago











  • the ones with the renewcommand (should be newcommand) around the #1 are known. Which others?
    – albert
    1 hour ago











  • @egreg Ooh, that explains the problem with the conditional. Same problem as in my question about docstrip a few weeks ago. I'm a slow learner :P
    – Phelype Oleinik
    1 hour ago







1




1




Load ifluatex before starting IfFileExists; otherwise ifluatex is not a conditional unless you are using luatex and therefore a missing conditional error ensues.
– egreg
1 hour ago




Load ifluatex before starting IfFileExists; otherwise ifluatex is not a conditional unless you are using luatex and therefore a missing conditional error ensues.
– egreg
1 hour ago












@egreg, but one still needs the double ##, correct?
– albert
1 hour ago




@egreg, but one still needs the double ##, correct?
– albert
1 hour ago












Yes, I was explaining the “apparently doesn't like the ifluatex conditional“ in Phelype's answer. By the way, you have several spurious spaces in your code.
– egreg
1 hour ago





Yes, I was explaining the “apparently doesn't like the ifluatex conditional“ in Phelype's answer. By the way, you have several spurious spaces in your code.
– egreg
1 hour ago













the ones with the renewcommand (should be newcommand) around the #1 are known. Which others?
– albert
1 hour ago





the ones with the renewcommand (should be newcommand) around the #1 are known. Which others?
– albert
1 hour ago













@egreg Ooh, that explains the problem with the conditional. Same problem as in my question about docstrip a few weeks ago. I'm a slow learner :P
– Phelype Oleinik
1 hour ago




@egreg Ooh, that explains the problem with the conditional. Same problem as in my question about docstrip a few weeks ago. I'm a slow learner :P
– Phelype Oleinik
1 hour ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










You need to double the parameter characters because IfFileExists grabs the true and false branch as arguments. Also, it apparently doesn't like the ifluatex conditional. You can use iftex's conditionals:



usepackageiftex
IfFileExists./emoji.sty
ifXeTeX
usepackage[bw,font=seguiemj.ttf]emoji
usepackagefontspec
else
ifLuaTeX
usepackage[bw,font=Symbola_hint.ttf]emoji
usepackagefontspec
else
usepackage[bw]emoji
fi
fi
newcommanddoxygenemoji[3]
IfFileExistsbw/##3.png
emoji##3

##1



newcommanddoxygenemoji[3] ##1



Or, to avoid doubling the parameter characters and for an extra degree of robustness you can use expl3's conditionals:



usepackageexpl3
ExplSyntaxOn
file_if_exist:nTF ./emoji.sty

sys_if_engine_xetex:T

usepackage[bw,font=seguiemj.ttf]emoji
usepackagefontspec

sys_if_engine_luatex:T

usepackage[bw,font=Symbola_hint.ttf]emoji
usepackagefontspec

sys_if_engine_pdftex:T

usepackage[bw]emoji

cs_new:Npn doxygenemoji #1 #2 #3

file_if_exist:nTF bw/#3.png

emoji #3

#1




cs_new:Npn doxygenemoji #1 #2 #3
##1

ExplSyntaxOff





share|improve this answer



























    up vote
    2
    down vote













    There are two errors in your code. The first is loading ifluatex inside a conditional; if the code is skipped (because the engine is XeLaTeX), ifluatex will not yet be a conditional, but an undefined token, resulting in an unbalanced conditional.



    The second error is not doubling # in the definition.



    I'd reorganize the code in a different fashion, avoiding complicated code in the true and false branches of IfFileExists.



    usepackageifluatex,ifxetex

    newififemoji
    IfFileExists./emoji.styemojitrueemojifalse

    ifemoji
    ifxetex
    usepackagefontspec
    PassOptionsToPackagefont=seguiemj.ttfemoji
    fi
    ifluatex
    usepackagefontspec
    PassOptionsToPackagefont=Symbola_hint.ttfemoji
    fi
    usepackage[bw]emoji
    newcommanddoxygenemoji[3]%
    IfFileExistsbw/#3.png%
    emoji#3%
    %
    #1%
    %

    else
    newcommanddoxygenemoji[3]#1
    fi





    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',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      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%2f452938%2fproblem-with-nested-if-statements%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote



      accepted










      You need to double the parameter characters because IfFileExists grabs the true and false branch as arguments. Also, it apparently doesn't like the ifluatex conditional. You can use iftex's conditionals:



      usepackageiftex
      IfFileExists./emoji.sty
      ifXeTeX
      usepackage[bw,font=seguiemj.ttf]emoji
      usepackagefontspec
      else
      ifLuaTeX
      usepackage[bw,font=Symbola_hint.ttf]emoji
      usepackagefontspec
      else
      usepackage[bw]emoji
      fi
      fi
      newcommanddoxygenemoji[3]
      IfFileExistsbw/##3.png
      emoji##3

      ##1



      newcommanddoxygenemoji[3] ##1



      Or, to avoid doubling the parameter characters and for an extra degree of robustness you can use expl3's conditionals:



      usepackageexpl3
      ExplSyntaxOn
      file_if_exist:nTF ./emoji.sty

      sys_if_engine_xetex:T

      usepackage[bw,font=seguiemj.ttf]emoji
      usepackagefontspec

      sys_if_engine_luatex:T

      usepackage[bw,font=Symbola_hint.ttf]emoji
      usepackagefontspec

      sys_if_engine_pdftex:T

      usepackage[bw]emoji

      cs_new:Npn doxygenemoji #1 #2 #3

      file_if_exist:nTF bw/#3.png

      emoji #3

      #1




      cs_new:Npn doxygenemoji #1 #2 #3
      ##1

      ExplSyntaxOff





      share|improve this answer
























        up vote
        3
        down vote



        accepted










        You need to double the parameter characters because IfFileExists grabs the true and false branch as arguments. Also, it apparently doesn't like the ifluatex conditional. You can use iftex's conditionals:



        usepackageiftex
        IfFileExists./emoji.sty
        ifXeTeX
        usepackage[bw,font=seguiemj.ttf]emoji
        usepackagefontspec
        else
        ifLuaTeX
        usepackage[bw,font=Symbola_hint.ttf]emoji
        usepackagefontspec
        else
        usepackage[bw]emoji
        fi
        fi
        newcommanddoxygenemoji[3]
        IfFileExistsbw/##3.png
        emoji##3

        ##1



        newcommanddoxygenemoji[3] ##1



        Or, to avoid doubling the parameter characters and for an extra degree of robustness you can use expl3's conditionals:



        usepackageexpl3
        ExplSyntaxOn
        file_if_exist:nTF ./emoji.sty

        sys_if_engine_xetex:T

        usepackage[bw,font=seguiemj.ttf]emoji
        usepackagefontspec

        sys_if_engine_luatex:T

        usepackage[bw,font=Symbola_hint.ttf]emoji
        usepackagefontspec

        sys_if_engine_pdftex:T

        usepackage[bw]emoji

        cs_new:Npn doxygenemoji #1 #2 #3

        file_if_exist:nTF bw/#3.png

        emoji #3

        #1




        cs_new:Npn doxygenemoji #1 #2 #3
        ##1

        ExplSyntaxOff





        share|improve this answer






















          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          You need to double the parameter characters because IfFileExists grabs the true and false branch as arguments. Also, it apparently doesn't like the ifluatex conditional. You can use iftex's conditionals:



          usepackageiftex
          IfFileExists./emoji.sty
          ifXeTeX
          usepackage[bw,font=seguiemj.ttf]emoji
          usepackagefontspec
          else
          ifLuaTeX
          usepackage[bw,font=Symbola_hint.ttf]emoji
          usepackagefontspec
          else
          usepackage[bw]emoji
          fi
          fi
          newcommanddoxygenemoji[3]
          IfFileExistsbw/##3.png
          emoji##3

          ##1



          newcommanddoxygenemoji[3] ##1



          Or, to avoid doubling the parameter characters and for an extra degree of robustness you can use expl3's conditionals:



          usepackageexpl3
          ExplSyntaxOn
          file_if_exist:nTF ./emoji.sty

          sys_if_engine_xetex:T

          usepackage[bw,font=seguiemj.ttf]emoji
          usepackagefontspec

          sys_if_engine_luatex:T

          usepackage[bw,font=Symbola_hint.ttf]emoji
          usepackagefontspec

          sys_if_engine_pdftex:T

          usepackage[bw]emoji

          cs_new:Npn doxygenemoji #1 #2 #3

          file_if_exist:nTF bw/#3.png

          emoji #3

          #1




          cs_new:Npn doxygenemoji #1 #2 #3
          ##1

          ExplSyntaxOff





          share|improve this answer












          You need to double the parameter characters because IfFileExists grabs the true and false branch as arguments. Also, it apparently doesn't like the ifluatex conditional. You can use iftex's conditionals:



          usepackageiftex
          IfFileExists./emoji.sty
          ifXeTeX
          usepackage[bw,font=seguiemj.ttf]emoji
          usepackagefontspec
          else
          ifLuaTeX
          usepackage[bw,font=Symbola_hint.ttf]emoji
          usepackagefontspec
          else
          usepackage[bw]emoji
          fi
          fi
          newcommanddoxygenemoji[3]
          IfFileExistsbw/##3.png
          emoji##3

          ##1



          newcommanddoxygenemoji[3] ##1



          Or, to avoid doubling the parameter characters and for an extra degree of robustness you can use expl3's conditionals:



          usepackageexpl3
          ExplSyntaxOn
          file_if_exist:nTF ./emoji.sty

          sys_if_engine_xetex:T

          usepackage[bw,font=seguiemj.ttf]emoji
          usepackagefontspec

          sys_if_engine_luatex:T

          usepackage[bw,font=Symbola_hint.ttf]emoji
          usepackagefontspec

          sys_if_engine_pdftex:T

          usepackage[bw]emoji

          cs_new:Npn doxygenemoji #1 #2 #3

          file_if_exist:nTF bw/#3.png

          emoji #3

          #1




          cs_new:Npn doxygenemoji #1 #2 #3
          ##1

          ExplSyntaxOff






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          Phelype Oleinik

          17.3k43770




          17.3k43770




















              up vote
              2
              down vote













              There are two errors in your code. The first is loading ifluatex inside a conditional; if the code is skipped (because the engine is XeLaTeX), ifluatex will not yet be a conditional, but an undefined token, resulting in an unbalanced conditional.



              The second error is not doubling # in the definition.



              I'd reorganize the code in a different fashion, avoiding complicated code in the true and false branches of IfFileExists.



              usepackageifluatex,ifxetex

              newififemoji
              IfFileExists./emoji.styemojitrueemojifalse

              ifemoji
              ifxetex
              usepackagefontspec
              PassOptionsToPackagefont=seguiemj.ttfemoji
              fi
              ifluatex
              usepackagefontspec
              PassOptionsToPackagefont=Symbola_hint.ttfemoji
              fi
              usepackage[bw]emoji
              newcommanddoxygenemoji[3]%
              IfFileExistsbw/#3.png%
              emoji#3%
              %
              #1%
              %

              else
              newcommanddoxygenemoji[3]#1
              fi





              share|improve this answer
























                up vote
                2
                down vote













                There are two errors in your code. The first is loading ifluatex inside a conditional; if the code is skipped (because the engine is XeLaTeX), ifluatex will not yet be a conditional, but an undefined token, resulting in an unbalanced conditional.



                The second error is not doubling # in the definition.



                I'd reorganize the code in a different fashion, avoiding complicated code in the true and false branches of IfFileExists.



                usepackageifluatex,ifxetex

                newififemoji
                IfFileExists./emoji.styemojitrueemojifalse

                ifemoji
                ifxetex
                usepackagefontspec
                PassOptionsToPackagefont=seguiemj.ttfemoji
                fi
                ifluatex
                usepackagefontspec
                PassOptionsToPackagefont=Symbola_hint.ttfemoji
                fi
                usepackage[bw]emoji
                newcommanddoxygenemoji[3]%
                IfFileExistsbw/#3.png%
                emoji#3%
                %
                #1%
                %

                else
                newcommanddoxygenemoji[3]#1
                fi





                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  There are two errors in your code. The first is loading ifluatex inside a conditional; if the code is skipped (because the engine is XeLaTeX), ifluatex will not yet be a conditional, but an undefined token, resulting in an unbalanced conditional.



                  The second error is not doubling # in the definition.



                  I'd reorganize the code in a different fashion, avoiding complicated code in the true and false branches of IfFileExists.



                  usepackageifluatex,ifxetex

                  newififemoji
                  IfFileExists./emoji.styemojitrueemojifalse

                  ifemoji
                  ifxetex
                  usepackagefontspec
                  PassOptionsToPackagefont=seguiemj.ttfemoji
                  fi
                  ifluatex
                  usepackagefontspec
                  PassOptionsToPackagefont=Symbola_hint.ttfemoji
                  fi
                  usepackage[bw]emoji
                  newcommanddoxygenemoji[3]%
                  IfFileExistsbw/#3.png%
                  emoji#3%
                  %
                  #1%
                  %

                  else
                  newcommanddoxygenemoji[3]#1
                  fi





                  share|improve this answer












                  There are two errors in your code. The first is loading ifluatex inside a conditional; if the code is skipped (because the engine is XeLaTeX), ifluatex will not yet be a conditional, but an undefined token, resulting in an unbalanced conditional.



                  The second error is not doubling # in the definition.



                  I'd reorganize the code in a different fashion, avoiding complicated code in the true and false branches of IfFileExists.



                  usepackageifluatex,ifxetex

                  newififemoji
                  IfFileExists./emoji.styemojitrueemojifalse

                  ifemoji
                  ifxetex
                  usepackagefontspec
                  PassOptionsToPackagefont=seguiemj.ttfemoji
                  fi
                  ifluatex
                  usepackagefontspec
                  PassOptionsToPackagefont=Symbola_hint.ttfemoji
                  fi
                  usepackage[bw]emoji
                  newcommanddoxygenemoji[3]%
                  IfFileExistsbw/#3.png%
                  emoji#3%
                  %
                  #1%
                  %

                  else
                  newcommanddoxygenemoji[3]#1
                  fi






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  egreg

                  685k8418273077




                  685k8418273077



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f452938%2fproblem-with-nested-if-statements%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      Long meetings (6-7 hours a day): Being “babysat” by supervisor

                      Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                      Confectionery