Math & Science ⇒ How do I define this command?
How do I define this command?
I want to make a command \en so that \en{x} gives \epsilon_{x} and \en gives \epsilon.
\newcommand{\en}[1]{\epsilon_{#1}} does not work because this will always take a argument.
\newcommand{\en}[1]{\epsilon_{#1}} does not work because this will always take a argument.
How do I define this command?
Hi,
try this:
try this:
Code: Select all
Code, edit and compile here:
\documentclass{book}\newcommand*{\en}[1][]{\epsilon\sb{#1}}\begin{document}$\en[x]$$\en$\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
How do I define this command?
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{xparse}\NewDocumentCommand\en{g}{%\IfNoValueTF#1{\epsilon}{\epsilon_{#1}}%}\begin{document}See \( \en \) but \( \en{a} \)!\end{document}
Joseph Wright
Re: How do I define this command?
Thx guys, I will use the short one.
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
Code, edit and compile here:\documentclass{article}\usepackage{xparse}\NewDocumentCommand\en{g}{%\IfNoValueTF#1{\epsilon}{\epsilon_{#1}}%}\begin{document}See \( \en \) but \( \en{a} \)!\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
-
- 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.
Joseph Wright
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
Code, edit and compile here:\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?
Use curly braces to enclose the bold-faced expresion:
Code: Select all
\( \en{{\mathbf{k}}} \)
1,1,2,3,5,8,13,21,34,55,89,144,233,...
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
Code, edit and compile here:\documentclass{article}\usepackage{xparse}\NewDocumentCommand\en{g}{%\IfNoValueTF#1{\epsilon}{\epsilon_{#1}}%}\begin{document}See \( \en \) but \( \en{a} \)!\end{document}
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{xparse}\NewDocumentCommand\en{g}{%\IfNoValueTF{#1}{\epsilon}{\epsilon_{#1}}%}\begin{document}See \( \en \) but \( \en{\textbf{k}} \)!\end{document}
Joseph Wright