Euler and minus sign
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
add a comment |
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
add a comment |
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
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
math-mode optional-arguments
edited 6 hours ago
Jesse op den Brouw
asked 6 hours ago
Jesse op den BrouwJesse op den Brouw
537119
537119
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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}
1
Exactly what i need. I changed the definition todefepowimaux#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
6 hours ago
@JesseopdenBrouw Thanks. And feel free to adapt to your need.
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw I might only suggest usingif jimaginaryunit
rather thanifimaginaryunit j
. Or better still,expandafterifximaginaryunit j
– Steven B. Segletes
6 hours ago
I see nothing wrong inifimaginaryunit j
, providedimaginaryunit
is eitheri
orj
. Oh, and did you tryepowim{-}
?;-)
– egreg
3 hours ago
@egreg I detect no problems withepowim{-}
. As to theif
test, you are right if the choices are alwaysi
orj
. But users have a tendency to do strange stuff, like something that expands toi
orj
, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.
– Steven B. Segletes
2 hours ago
add a comment |
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}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%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
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}
1
Exactly what i need. I changed the definition todefepowimaux#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
6 hours ago
@JesseopdenBrouw Thanks. And feel free to adapt to your need.
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw I might only suggest usingif jimaginaryunit
rather thanifimaginaryunit j
. Or better still,expandafterifximaginaryunit j
– Steven B. Segletes
6 hours ago
I see nothing wrong inifimaginaryunit j
, providedimaginaryunit
is eitheri
orj
. Oh, and did you tryepowim{-}
?;-)
– egreg
3 hours ago
@egreg I detect no problems withepowim{-}
. As to theif
test, you are right if the choices are alwaysi
orj
. But users have a tendency to do strange stuff, like something that expands toi
orj
, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.
– Steven B. Segletes
2 hours ago
add a comment |
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}
1
Exactly what i need. I changed the definition todefepowimaux#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
6 hours ago
@JesseopdenBrouw Thanks. And feel free to adapt to your need.
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw I might only suggest usingif jimaginaryunit
rather thanifimaginaryunit j
. Or better still,expandafterifximaginaryunit j
– Steven B. Segletes
6 hours ago
I see nothing wrong inifimaginaryunit j
, providedimaginaryunit
is eitheri
orj
. Oh, and did you tryepowim{-}
?;-)
– egreg
3 hours ago
@egreg I detect no problems withepowim{-}
. As to theif
test, you are right if the choices are alwaysi
orj
. But users have a tendency to do strange stuff, like something that expands toi
orj
, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.
– Steven B. Segletes
2 hours ago
add a comment |
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}
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}
edited 1 hour ago
answered 6 hours ago
Steven B. SegletesSteven B. Segletes
156k9201411
156k9201411
1
Exactly what i need. I changed the definition todefepowimaux#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
6 hours ago
@JesseopdenBrouw Thanks. And feel free to adapt to your need.
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw I might only suggest usingif jimaginaryunit
rather thanifimaginaryunit j
. Or better still,expandafterifximaginaryunit j
– Steven B. Segletes
6 hours ago
I see nothing wrong inifimaginaryunit j
, providedimaginaryunit
is eitheri
orj
. Oh, and did you tryepowim{-}
?;-)
– egreg
3 hours ago
@egreg I detect no problems withepowim{-}
. As to theif
test, you are right if the choices are alwaysi
orj
. But users have a tendency to do strange stuff, like something that expands toi
orj
, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.
– Steven B. Segletes
2 hours ago
add a comment |
1
Exactly what i need. I changed the definition todefepowimaux#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
6 hours ago
@JesseopdenBrouw Thanks. And feel free to adapt to your need.
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw I might only suggest usingif jimaginaryunit
rather thanifimaginaryunit j
. Or better still,expandafterifximaginaryunit j
– Steven B. Segletes
6 hours ago
I see nothing wrong inifimaginaryunit j
, providedimaginaryunit
is eitheri
orj
. Oh, and did you tryepowim{-}
?;-)
– egreg
3 hours ago
@egreg I detect no problems withepowim{-}
. As to theif
test, you are right if the choices are alwaysi
orj
. But users have a tendency to do strange stuff, like something that expands toi
orj
, or a different letter or symbol altogether, etc. I was trying to head off crazy stuff.
– Steven B. Segletes
2 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
6 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
6 hours ago
@JesseopdenBrouw Thanks. And feel free to adapt to your need.
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw Thanks. And feel free to adapt to your need.
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw I might only suggest using
if jimaginaryunit
rather than ifimaginaryunit j
. Or better still, expandafterifximaginaryunit j
– Steven B. Segletes
6 hours ago
@JesseopdenBrouw I might only suggest using
if jimaginaryunit
rather than ifimaginaryunit j
. Or better still, expandafterifximaginaryunit j
– Steven B. Segletes
6 hours ago
I see nothing wrong in
ifimaginaryunit j
, provided imaginaryunit
is either i
or j
. Oh, and did you try epowim{-}
? ;-)
– egreg
3 hours ago
I see nothing wrong in
ifimaginaryunit j
, provided imaginaryunit
is either i
or j
. Oh, and did you try epowim{-}
? ;-)
– egreg
3 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
2 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
2 hours ago
add a comment |
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}
add a comment |
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}
add a comment |
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}
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}
edited 3 hours ago
answered 4 hours ago
egregegreg
721k8719113210
721k8719113210
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476045%2feuler-and-minus-sign%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