If you want to change the part with the t, leaving P the default, you should try to evaluate, which event will be more often.
If you often need to change t, not P, you should simply change the order, in which they are used.
A LaTeX macro doesn't need a mandatory argument, don't think of it as a mathematical function, but as Lego building blocks.
In the code below are examples, why i put mean/min/max within
\text{ }
. They are words, and therefor text. Not using text for them makes them individual
variables
You can read about ensuremath at
http://tex.stackexchange.com/questions/ ... math-macro
Code: Select all
\documentclass{article}
\usepackage{mathtools}
\usepackage{xparse}
\usepackage{blindtext}
\usepackage{physics}
\NewDocumentCommand{\term} {
O {P_\text{mean}}%optional, defaults to P
O {t}%optional, defaults to t
} {
\frac{#1 V_{\text{SE}} \, \pi c #2 \cdot \sin a }
{1+\sqrt{1-c^2} } }
%Taking the fraction as a mandatory argument:
\NewDocumentCommand{\fullterm} {
O {P_\text{mean}}%optional, defaults to P
O {t}%optional, defaults to t
m
} {
\frac{#1 V_{\text{SE}} \, \pi c #2 \cdot \sin a }
{1+\sqrt{1-c^2} } \cdot #3 }
\begin{document}
\[ \term \]
\[ \term[P] \]
\[ \term[P_\text{min}][2t] \]
Pay attention, if you want to leave out the P (default instead)
but want to change the t part.
\[ \term[t^3] \]
\[ \term[][t^2] \]
\begin{align*}
W_c = \oint P \dd{V_c} &=%Have a look at package physics
- \term\\
&= - \term[P_\text{min}] \cdot
\frac{\sqrt{1+c}}{\sqrt{1-c}}\\
&= -\term[P_\text{max}] \cdot
\frac{\sqrt{1-c}}{\sqrt{1+c}}
\end{align*}
What happens if we want to use our command in text?
Try it out by deleting the comment sign %\term
Usually, having ensuremath in your document is discouraged.
Remember, you can still do $\term$. Please compare both outputs.
\NewDocumentCommand {\Pmin} {} {P_\text{min} }
\NewDocumentCommand {\Pmax} {} {P_\text{max} }
\NewDocumentCommand {\Pmean} {} {P_\text{mean} }
Using fullterm now:
\begin{align*}
W_c = \oint P \dd{V_c} &=%Have a look at package physics
- \term\\
&= - \fullterm[\Pmin]{\frac{\sqrt{1+c}}{\sqrt{1-c}}}\\
&= -\fullterm[\Pmax]{\frac{\sqrt{1-c}}{\sqrt{1+c}}}
\end{align*}
Comparing text and variables:
\begin{align*}
P_{min} & \Pmin \\%defined above
P_{mean} & \Pmean
\end{align*}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.