Euler and minus sign












9















I'm trying to define a macro to typeset Eulers complex e-power with or without a minus sign in its argument. I would like the macro to automatically detect if its argument starts with a -. I have the following MWE which uses and optional argument:



documentclass[a4paper,12pt,fleqn]{article}

defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
defimunit{mathrm{imaginaryunit}} % ... in upright math
defce{mathrm{e}} % the constant e, upright of course
makeatletter
defepowim{@ifnextchar[{epowimi}{epowimi}} % e to-the-power-of imaginary unit
defepowimi[#1]#2{ce^{#1ifimaginaryunit jrelax,fiimunit#2}} % e to-the-power-of imaginary unit
makeatother

begin{document}

begin{equation}
epowim{alpha}qquad epowim[-]{alpha} qquad ce^{-imunitalpha}
end{equation}

end{document}


So I would like a macro that detects if its argument starts with a -:



epowim{-alpha}


should detect the - and place it before the imaginary unit instead of placing it after the imaginary unit.



So the question is if it can be done and how.










share|improve this question





























    9















    I'm trying to define a macro to typeset Eulers complex e-power with or without a minus sign in its argument. I would like the macro to automatically detect if its argument starts with a -. I have the following MWE which uses and optional argument:



    documentclass[a4paper,12pt,fleqn]{article}

    defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
    defimunit{mathrm{imaginaryunit}} % ... in upright math
    defce{mathrm{e}} % the constant e, upright of course
    makeatletter
    defepowim{@ifnextchar[{epowimi}{epowimi}} % e to-the-power-of imaginary unit
    defepowimi[#1]#2{ce^{#1ifimaginaryunit jrelax,fiimunit#2}} % e to-the-power-of imaginary unit
    makeatother

    begin{document}

    begin{equation}
    epowim{alpha}qquad epowim[-]{alpha} qquad ce^{-imunitalpha}
    end{equation}

    end{document}


    So I would like a macro that detects if its argument starts with a -:



    epowim{-alpha}


    should detect the - and place it before the imaginary unit instead of placing it after the imaginary unit.



    So the question is if it can be done and how.










    share|improve this question



























      9












      9








      9


      0






      I'm trying to define a macro to typeset Eulers complex e-power with or without a minus sign in its argument. I would like the macro to automatically detect if its argument starts with a -. I have the following MWE which uses and optional argument:



      documentclass[a4paper,12pt,fleqn]{article}

      defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
      defimunit{mathrm{imaginaryunit}} % ... in upright math
      defce{mathrm{e}} % the constant e, upright of course
      makeatletter
      defepowim{@ifnextchar[{epowimi}{epowimi}} % e to-the-power-of imaginary unit
      defepowimi[#1]#2{ce^{#1ifimaginaryunit jrelax,fiimunit#2}} % e to-the-power-of imaginary unit
      makeatother

      begin{document}

      begin{equation}
      epowim{alpha}qquad epowim[-]{alpha} qquad ce^{-imunitalpha}
      end{equation}

      end{document}


      So I would like a macro that detects if its argument starts with a -:



      epowim{-alpha}


      should detect the - and place it before the imaginary unit instead of placing it after the imaginary unit.



      So the question is if it can be done and how.










      share|improve this question
















      I'm trying to define a macro to typeset Eulers complex e-power with or without a minus sign in its argument. I would like the macro to automatically detect if its argument starts with a -. I have the following MWE which uses and optional argument:



      documentclass[a4paper,12pt,fleqn]{article}

      defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
      defimunit{mathrm{imaginaryunit}} % ... in upright math
      defce{mathrm{e}} % the constant e, upright of course
      makeatletter
      defepowim{@ifnextchar[{epowimi}{epowimi}} % e to-the-power-of imaginary unit
      defepowimi[#1]#2{ce^{#1ifimaginaryunit jrelax,fiimunit#2}} % e to-the-power-of imaginary unit
      makeatother

      begin{document}

      begin{equation}
      epowim{alpha}qquad epowim[-]{alpha} qquad ce^{-imunitalpha}
      end{equation}

      end{document}


      So I would like a macro that detects if its argument starts with a -:



      epowim{-alpha}


      should detect the - and place it before the imaginary unit instead of placing it after the imaginary unit.



      So the question is if it can be done and how.







      math-mode optional-arguments






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 10 hours ago







      Jesse op den Brouw

















      asked 10 hours ago









      Jesse op den BrouwJesse op den Brouw

      542119




      542119






















          2 Answers
          2






          active

          oldest

          votes


















          7














          Something like this?



          documentclass[a4paper,12pt,fleqn]{article}
          defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
          defimunit{mathrm{imaginaryunit}} % ... in upright math
          defce{mathrm{e}} % the constant e, upright of course
          newcommandepowim[1]{ce^{epowimaux#1relaxendep}}
          defepowimaux#1#2endep{ifx-#1relax-imunitelse%
          if jimaginaryunitrelax,fiimunit#1fi#2}
          begin{document}
          [
          epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
          ]
          [
          epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
          ]
          defimaginaryunit{i}
          [
          epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
          ]
          [
          epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
          ]
          end{document}


          enter image description here






          share|improve this answer





















          • 1





            Exactly what i need. I changed the definition to defepowimaux#1#2endep{ifx-#1relax-imunitelseifimaginaryunit jrelax,fiimunit#1fi#2} to compensate for the fact that the j is too close to the e but not when using i as imaginary unit

            – Jesse op den Brouw
            9 hours ago













          • @JesseopdenBrouw Thanks. And feel free to adapt to your need.

            – Steven B. Segletes
            9 hours ago











          • @JesseopdenBrouw I might only suggest using if jimaginaryunit rather than ifimaginaryunit j. Or better still, expandafterifximaginaryunit j

            – Steven B. Segletes
            9 hours ago











          • I see nothing wrong in ifimaginaryunit j, provided imaginaryunit is either i or j. Oh, and did you try epowim{-}? ;-)

            – egreg
            7 hours ago











          • @egreg I detect no problems with epowim{-}. As to the if test, you are right if the choices are always i or j. But users have a tendency to do strange stuff, like something that expands to i or j, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.

            – Steven B. Segletes
            5 hours ago



















          3














          Avoid def, your life will be easier.



          Since you seem to know about @ifnextchar:



          documentclass[a4paper,12pt,fleqn]{article}

          % the imaginary unit, j for engineers and i for the rest of the world
          newcommandimaginaryunit{j}
          % in upright type as engineers do; also Euler's constant
          newcommandimunit{mathrm{imaginaryunit}}
          newcommandce{mathrm{e}}

          newcommand{fiximunit}{ifimaginaryunit j,fi}

          makeatletter
          newcommand{epowim}[1]{ce^{epowim@#1}}
          newcommand{epowim@}{@ifnextchar-{epowim@@}{epowim@@{fiximunit}}}
          newcommand{epowim@@}[1]{#1imunit}
          makeatother

          begin{document}

          begin{equation}
          epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
          qquad epowim{} qquad epowim{-}
          end{equation}

          end{document}


          Explanation: @ifnextchar- uses the next argument if - is found, the successive one otherwise, but without removing -. So if - is called the result will be



          epowim@@-alpha


          which passes - as argument to epowim@@. Otherwise epowim@@ is called with fiximunit as argument.



          This would not fail with epowim{} or epowim{-} to typeset ej and e−j respectively.



          A perhaps simpler implementation with xparse:



          documentclass[a4paper,12pt,fleqn]{article}

          usepackage{xparse}

          % the imaginary unit, j for engineers and i for the rest of the world
          newcommandimaginaryunit{j}
          % in upright type as engineers do; also Euler's constant
          newcommandimunit{mathrm{imaginaryunit}}
          newcommandce{mathrm{e}}

          newcommand{fiximunit}{ifimaginaryunit j,fi}

          NewDocumentCommand{epowim}{m}{ce^{powim#1}}
          NewDocumentCommand{powim}{t-}{IfBooleanTF{#1}{-imunit}{fiximunitimunit}}

          begin{document}

          begin{equation}
          epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
          qquad epowim{} qquad epowim{-}
          end{equation}

          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%2f476045%2feuler-and-minus-sign%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









            7














            Something like this?



            documentclass[a4paper,12pt,fleqn]{article}
            defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
            defimunit{mathrm{imaginaryunit}} % ... in upright math
            defce{mathrm{e}} % the constant e, upright of course
            newcommandepowim[1]{ce^{epowimaux#1relaxendep}}
            defepowimaux#1#2endep{ifx-#1relax-imunitelse%
            if jimaginaryunitrelax,fiimunit#1fi#2}
            begin{document}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            defimaginaryunit{i}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            end{document}


            enter image description here






            share|improve this answer





















            • 1





              Exactly what i need. I changed the definition to defepowimaux#1#2endep{ifx-#1relax-imunitelseifimaginaryunit jrelax,fiimunit#1fi#2} to compensate for the fact that the j is too close to the e but not when using i as imaginary unit

              – Jesse op den Brouw
              9 hours ago













            • @JesseopdenBrouw Thanks. And feel free to adapt to your need.

              – Steven B. Segletes
              9 hours ago











            • @JesseopdenBrouw I might only suggest using if jimaginaryunit rather than ifimaginaryunit j. Or better still, expandafterifximaginaryunit j

              – Steven B. Segletes
              9 hours ago











            • I see nothing wrong in ifimaginaryunit j, provided imaginaryunit is either i or j. Oh, and did you try epowim{-}? ;-)

              – egreg
              7 hours ago











            • @egreg I detect no problems with epowim{-}. As to the if test, you are right if the choices are always i or j. But users have a tendency to do strange stuff, like something that expands to i or j, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.

              – Steven B. Segletes
              5 hours ago
















            7














            Something like this?



            documentclass[a4paper,12pt,fleqn]{article}
            defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
            defimunit{mathrm{imaginaryunit}} % ... in upright math
            defce{mathrm{e}} % the constant e, upright of course
            newcommandepowim[1]{ce^{epowimaux#1relaxendep}}
            defepowimaux#1#2endep{ifx-#1relax-imunitelse%
            if jimaginaryunitrelax,fiimunit#1fi#2}
            begin{document}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            defimaginaryunit{i}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            end{document}


            enter image description here






            share|improve this answer





















            • 1





              Exactly what i need. I changed the definition to defepowimaux#1#2endep{ifx-#1relax-imunitelseifimaginaryunit jrelax,fiimunit#1fi#2} to compensate for the fact that the j is too close to the e but not when using i as imaginary unit

              – Jesse op den Brouw
              9 hours ago













            • @JesseopdenBrouw Thanks. And feel free to adapt to your need.

              – Steven B. Segletes
              9 hours ago











            • @JesseopdenBrouw I might only suggest using if jimaginaryunit rather than ifimaginaryunit j. Or better still, expandafterifximaginaryunit j

              – Steven B. Segletes
              9 hours ago











            • I see nothing wrong in ifimaginaryunit j, provided imaginaryunit is either i or j. Oh, and did you try epowim{-}? ;-)

              – egreg
              7 hours ago











            • @egreg I detect no problems with epowim{-}. As to the if test, you are right if the choices are always i or j. But users have a tendency to do strange stuff, like something that expands to i or j, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.

              – Steven B. Segletes
              5 hours ago














            7












            7








            7







            Something like this?



            documentclass[a4paper,12pt,fleqn]{article}
            defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
            defimunit{mathrm{imaginaryunit}} % ... in upright math
            defce{mathrm{e}} % the constant e, upright of course
            newcommandepowim[1]{ce^{epowimaux#1relaxendep}}
            defepowimaux#1#2endep{ifx-#1relax-imunitelse%
            if jimaginaryunitrelax,fiimunit#1fi#2}
            begin{document}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            defimaginaryunit{i}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            end{document}


            enter image description here






            share|improve this answer















            Something like this?



            documentclass[a4paper,12pt,fleqn]{article}
            defimaginaryunit{j} % the imaginary unit, i for mathematician and theoretical physicist, j for the rest of the world.
            defimunit{mathrm{imaginaryunit}} % ... in upright math
            defce{mathrm{e}} % the constant e, upright of course
            newcommandepowim[1]{ce^{epowimaux#1relaxendep}}
            defepowimaux#1#2endep{ifx-#1relax-imunitelse%
            if jimaginaryunitrelax,fiimunit#1fi#2}
            begin{document}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            defimaginaryunit{i}
            [
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            ]
            [
            epowim{x+t}quadepowim{-x+t}quadepowim{-}quadepowim{}
            ]
            end{document}


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 4 hours ago

























            answered 10 hours ago









            Steven B. SegletesSteven B. Segletes

            156k9201411




            156k9201411








            • 1





              Exactly what i need. I changed the definition to defepowimaux#1#2endep{ifx-#1relax-imunitelseifimaginaryunit jrelax,fiimunit#1fi#2} to compensate for the fact that the j is too close to the e but not when using i as imaginary unit

              – Jesse op den Brouw
              9 hours ago













            • @JesseopdenBrouw Thanks. And feel free to adapt to your need.

              – Steven B. Segletes
              9 hours ago











            • @JesseopdenBrouw I might only suggest using if jimaginaryunit rather than ifimaginaryunit j. Or better still, expandafterifximaginaryunit j

              – Steven B. Segletes
              9 hours ago











            • I see nothing wrong in ifimaginaryunit j, provided imaginaryunit is either i or j. Oh, and did you try epowim{-}? ;-)

              – egreg
              7 hours ago











            • @egreg I detect no problems with epowim{-}. As to the if test, you are right if the choices are always i or j. But users have a tendency to do strange stuff, like something that expands to i or j, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.

              – Steven B. Segletes
              5 hours ago














            • 1





              Exactly what i need. I changed the definition to defepowimaux#1#2endep{ifx-#1relax-imunitelseifimaginaryunit jrelax,fiimunit#1fi#2} to compensate for the fact that the j is too close to the e but not when using i as imaginary unit

              – Jesse op den Brouw
              9 hours ago













            • @JesseopdenBrouw Thanks. And feel free to adapt to your need.

              – Steven B. Segletes
              9 hours ago











            • @JesseopdenBrouw I might only suggest using if jimaginaryunit rather than ifimaginaryunit j. Or better still, expandafterifximaginaryunit j

              – Steven B. Segletes
              9 hours ago











            • I see nothing wrong in ifimaginaryunit j, provided imaginaryunit is either i or j. Oh, and did you try epowim{-}? ;-)

              – egreg
              7 hours ago











            • @egreg I detect no problems with epowim{-}. As to the if test, you are right if the choices are always i or j. But users have a tendency to do strange stuff, like something that expands to i or j, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.

              – Steven B. Segletes
              5 hours ago








            1




            1





            Exactly what i need. I changed the definition to defepowimaux#1#2endep{ifx-#1relax-imunitelseifimaginaryunit jrelax,fiimunit#1fi#2} to compensate for the fact that the j is too close to the e but not when using i as imaginary unit

            – Jesse op den Brouw
            9 hours ago







            Exactly what i need. I changed the definition to defepowimaux#1#2endep{ifx-#1relax-imunitelseifimaginaryunit jrelax,fiimunit#1fi#2} to compensate for the fact that the j is too close to the e but not when using i as imaginary unit

            – Jesse op den Brouw
            9 hours ago















            @JesseopdenBrouw Thanks. And feel free to adapt to your need.

            – Steven B. Segletes
            9 hours ago





            @JesseopdenBrouw Thanks. And feel free to adapt to your need.

            – Steven B. Segletes
            9 hours ago













            @JesseopdenBrouw I might only suggest using if jimaginaryunit rather than ifimaginaryunit j. Or better still, expandafterifximaginaryunit j

            – Steven B. Segletes
            9 hours ago





            @JesseopdenBrouw I might only suggest using if jimaginaryunit rather than ifimaginaryunit j. Or better still, expandafterifximaginaryunit j

            – Steven B. Segletes
            9 hours ago













            I see nothing wrong in ifimaginaryunit j, provided imaginaryunit is either i or j. Oh, and did you try epowim{-}? ;-)

            – egreg
            7 hours ago





            I see nothing wrong in ifimaginaryunit j, provided imaginaryunit is either i or j. Oh, and did you try epowim{-}? ;-)

            – egreg
            7 hours ago













            @egreg I detect no problems with epowim{-}. As to the if test, you are right if the choices are always i or j. But users have a tendency to do strange stuff, like something that expands to i or j, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.

            – Steven B. Segletes
            5 hours ago





            @egreg I detect no problems with epowim{-}. As to the if test, you are right if the choices are always i or j. But users have a tendency to do strange stuff, like something that expands to i or j, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.

            – Steven B. Segletes
            5 hours ago











            3














            Avoid def, your life will be easier.



            Since you seem to know about @ifnextchar:



            documentclass[a4paper,12pt,fleqn]{article}

            % the imaginary unit, j for engineers and i for the rest of the world
            newcommandimaginaryunit{j}
            % in upright type as engineers do; also Euler's constant
            newcommandimunit{mathrm{imaginaryunit}}
            newcommandce{mathrm{e}}

            newcommand{fiximunit}{ifimaginaryunit j,fi}

            makeatletter
            newcommand{epowim}[1]{ce^{epowim@#1}}
            newcommand{epowim@}{@ifnextchar-{epowim@@}{epowim@@{fiximunit}}}
            newcommand{epowim@@}[1]{#1imunit}
            makeatother

            begin{document}

            begin{equation}
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            qquad epowim{} qquad epowim{-}
            end{equation}

            end{document}


            Explanation: @ifnextchar- uses the next argument if - is found, the successive one otherwise, but without removing -. So if - is called the result will be



            epowim@@-alpha


            which passes - as argument to epowim@@. Otherwise epowim@@ is called with fiximunit as argument.



            This would not fail with epowim{} or epowim{-} to typeset ej and e−j respectively.



            A perhaps simpler implementation with xparse:



            documentclass[a4paper,12pt,fleqn]{article}

            usepackage{xparse}

            % the imaginary unit, j for engineers and i for the rest of the world
            newcommandimaginaryunit{j}
            % in upright type as engineers do; also Euler's constant
            newcommandimunit{mathrm{imaginaryunit}}
            newcommandce{mathrm{e}}

            newcommand{fiximunit}{ifimaginaryunit j,fi}

            NewDocumentCommand{epowim}{m}{ce^{powim#1}}
            NewDocumentCommand{powim}{t-}{IfBooleanTF{#1}{-imunit}{fiximunitimunit}}

            begin{document}

            begin{equation}
            epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
            qquad epowim{} qquad epowim{-}
            end{equation}

            end{document}


            enter image description here






            share|improve this answer






























              3














              Avoid def, your life will be easier.



              Since you seem to know about @ifnextchar:



              documentclass[a4paper,12pt,fleqn]{article}

              % the imaginary unit, j for engineers and i for the rest of the world
              newcommandimaginaryunit{j}
              % in upright type as engineers do; also Euler's constant
              newcommandimunit{mathrm{imaginaryunit}}
              newcommandce{mathrm{e}}

              newcommand{fiximunit}{ifimaginaryunit j,fi}

              makeatletter
              newcommand{epowim}[1]{ce^{epowim@#1}}
              newcommand{epowim@}{@ifnextchar-{epowim@@}{epowim@@{fiximunit}}}
              newcommand{epowim@@}[1]{#1imunit}
              makeatother

              begin{document}

              begin{equation}
              epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
              qquad epowim{} qquad epowim{-}
              end{equation}

              end{document}


              Explanation: @ifnextchar- uses the next argument if - is found, the successive one otherwise, but without removing -. So if - is called the result will be



              epowim@@-alpha


              which passes - as argument to epowim@@. Otherwise epowim@@ is called with fiximunit as argument.



              This would not fail with epowim{} or epowim{-} to typeset ej and e−j respectively.



              A perhaps simpler implementation with xparse:



              documentclass[a4paper,12pt,fleqn]{article}

              usepackage{xparse}

              % the imaginary unit, j for engineers and i for the rest of the world
              newcommandimaginaryunit{j}
              % in upright type as engineers do; also Euler's constant
              newcommandimunit{mathrm{imaginaryunit}}
              newcommandce{mathrm{e}}

              newcommand{fiximunit}{ifimaginaryunit j,fi}

              NewDocumentCommand{epowim}{m}{ce^{powim#1}}
              NewDocumentCommand{powim}{t-}{IfBooleanTF{#1}{-imunit}{fiximunitimunit}}

              begin{document}

              begin{equation}
              epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
              qquad epowim{} qquad epowim{-}
              end{equation}

              end{document}


              enter image description here






              share|improve this answer




























                3












                3








                3







                Avoid def, your life will be easier.



                Since you seem to know about @ifnextchar:



                documentclass[a4paper,12pt,fleqn]{article}

                % the imaginary unit, j for engineers and i for the rest of the world
                newcommandimaginaryunit{j}
                % in upright type as engineers do; also Euler's constant
                newcommandimunit{mathrm{imaginaryunit}}
                newcommandce{mathrm{e}}

                newcommand{fiximunit}{ifimaginaryunit j,fi}

                makeatletter
                newcommand{epowim}[1]{ce^{epowim@#1}}
                newcommand{epowim@}{@ifnextchar-{epowim@@}{epowim@@{fiximunit}}}
                newcommand{epowim@@}[1]{#1imunit}
                makeatother

                begin{document}

                begin{equation}
                epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
                qquad epowim{} qquad epowim{-}
                end{equation}

                end{document}


                Explanation: @ifnextchar- uses the next argument if - is found, the successive one otherwise, but without removing -. So if - is called the result will be



                epowim@@-alpha


                which passes - as argument to epowim@@. Otherwise epowim@@ is called with fiximunit as argument.



                This would not fail with epowim{} or epowim{-} to typeset ej and e−j respectively.



                A perhaps simpler implementation with xparse:



                documentclass[a4paper,12pt,fleqn]{article}

                usepackage{xparse}

                % the imaginary unit, j for engineers and i for the rest of the world
                newcommandimaginaryunit{j}
                % in upright type as engineers do; also Euler's constant
                newcommandimunit{mathrm{imaginaryunit}}
                newcommandce{mathrm{e}}

                newcommand{fiximunit}{ifimaginaryunit j,fi}

                NewDocumentCommand{epowim}{m}{ce^{powim#1}}
                NewDocumentCommand{powim}{t-}{IfBooleanTF{#1}{-imunit}{fiximunitimunit}}

                begin{document}

                begin{equation}
                epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
                qquad epowim{} qquad epowim{-}
                end{equation}

                end{document}


                enter image description here






                share|improve this answer















                Avoid def, your life will be easier.



                Since you seem to know about @ifnextchar:



                documentclass[a4paper,12pt,fleqn]{article}

                % the imaginary unit, j for engineers and i for the rest of the world
                newcommandimaginaryunit{j}
                % in upright type as engineers do; also Euler's constant
                newcommandimunit{mathrm{imaginaryunit}}
                newcommandce{mathrm{e}}

                newcommand{fiximunit}{ifimaginaryunit j,fi}

                makeatletter
                newcommand{epowim}[1]{ce^{epowim@#1}}
                newcommand{epowim@}{@ifnextchar-{epowim@@}{epowim@@{fiximunit}}}
                newcommand{epowim@@}[1]{#1imunit}
                makeatother

                begin{document}

                begin{equation}
                epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
                qquad epowim{} qquad epowim{-}
                end{equation}

                end{document}


                Explanation: @ifnextchar- uses the next argument if - is found, the successive one otherwise, but without removing -. So if - is called the result will be



                epowim@@-alpha


                which passes - as argument to epowim@@. Otherwise epowim@@ is called with fiximunit as argument.



                This would not fail with epowim{} or epowim{-} to typeset ej and e−j respectively.



                A perhaps simpler implementation with xparse:



                documentclass[a4paper,12pt,fleqn]{article}

                usepackage{xparse}

                % the imaginary unit, j for engineers and i for the rest of the world
                newcommandimaginaryunit{j}
                % in upright type as engineers do; also Euler's constant
                newcommandimunit{mathrm{imaginaryunit}}
                newcommandce{mathrm{e}}

                newcommand{fiximunit}{ifimaginaryunit j,fi}

                NewDocumentCommand{epowim}{m}{ce^{powim#1}}
                NewDocumentCommand{powim}{t-}{IfBooleanTF{#1}{-imunit}{fiximunitimunit}}

                begin{document}

                begin{equation}
                epowim{alpha}qquad epowim{-alpha} qquad ce^{-imunitalpha}
                qquad epowim{} qquad epowim{-}
                end{equation}

                end{document}


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 7 hours ago

























                answered 8 hours ago









                egregegreg

                721k8719113210




                721k8719113210






























                    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%2f476045%2feuler-and-minus-sign%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

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    RAC Tourist Trophy