Math & Science ⇒ How do I define this command?
How do I define this command?
\newcommand{\en}[1]{\epsilon_{#1}} does not work because this will always take a argument.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
How do I define this command?
try this:
Code: Select all
\documentclass{book}
\newcommand*{\en}[1][]{\epsilon\sb{#1}}
\begin{document}
$\en[x]$
$\en$
\end{document}
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
How do I define this command?
Code: Select all
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand\en{g}{%
\IfNoValueTF#1{\epsilon}{\epsilon_{#1}}%
}
\begin{document}
See \( \en \) but \( \en{a} \)!
\end{document}
Re: How do I define this command?
How do I define this command?
Thank you, Joseph, for bringing the xparse package to my attention; even with this short example I can tell I like it (the syntax for both the command definition and for the command "in action" is more "natural"). In my free time (if any) I will have a look at the packages from the xpackage bundle.josephwright wrote:Code: Select all
\documentclass{article} \usepackage{xparse} \NewDocumentCommand\en{g}{% \IfNoValueTF#1{\epsilon}{\epsilon_{#1}}% } \begin{document} See \( \en \) but \( \en{a} \)! \end{document}
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
How do I define this command?
Not a problem. I can't claim to have had the ideas for xparse, but I did write a lot the current implementation, so I do hope it is useful.gmedina wrote: Thank you, Joseph, for bringing the xparse package to my attention; even with this short example I can tell I like it (the syntax for both the command definition and for the command "in action" is more "natural"). In my free time (if any) I will have a look at the packages from the xpackage bundle.
How do I define this command?
This works, but when I use \en{\textbf{k}}, it gives me two \epsilons. Is there no easy way to do \en{\textbf{k}} and \en?josephwright wrote:Code: Select all
\documentclass{article} \usepackage{xparse} \NewDocumentCommand\en{g}{% \IfNoValueTF#1{\epsilon}{\epsilon_{#1}}% } \begin{document} See \( \en \) but \( \en{a} \)! \end{document}
Maybe it is best I use \newcommand{\en}[1]{\epsilon_{#1}} and use \epsilon for normal.
How do I define this command?
Code: Select all
\( \en{{\mathbf{k}}} \)
How do I define this command?
Okay thx for your help, but I have already used \en{\mathbf{k}} like 100 times in my project, hard to change it all:P. In the other posters idea I have to use \en[] instead of \en{}, hard to change as well.gmedina wrote:Use curly braces to enclose the bold-faced expresion:
Code: Select all
\( \en{{\mathbf{k}}} \)
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
How do I define this command?
Sorry, my error in the definition above. TryYue wrote:This works, but when I use \en{\textbf{k}}, it gives me two \epsilons. Is there no easy way to do \en{\textbf{k}} and \en?josephwright wrote:Code: Select all
\documentclass{article} \usepackage{xparse} \NewDocumentCommand\en{g}{% \IfNoValueTF#1{\epsilon}{\epsilon_{#1}}% } \begin{document} See \( \en \) but \( \en{a} \)! \end{document}
Code: Select all
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand\en{g}{%
\IfNoValueTF{#1}{\epsilon}{\epsilon_{#1}}%
}
\begin{document}
See \( \en \) but \( \en{\textbf{k}} \)!
\end{document}