TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a simple macro using TeX with optional parameters:


I understand a common way is to use \futurelet. So far the code is as follows:


\def\elidebefore[#1]#2{[$\ldots$] #2}

\def\elide {%

% The \choosemacro, based on
% the lookahead of \elide, calls
% either \elidebefore or \elideafter 

 \ifx\ifoptions [%
     \let\choice = \elidebefore 
    \let\choice = \elideafter

Testing \elide[b]{Lorem ipsum}

\elide{Lorem Ipsum}

\elide[b]{Lorem ipsum}


This works ... but since I am only checking if the square bracket exists and switching to either macro1 or macro2 elide[]{} will work with anything in-between the square brackets. How, can I extend the macro to read the letters between the square brackets?

Is there a predefined LaTeX macro that one can use? (I know about keyval, but I just prefer to do this with basic commands).

share|improve this question
I am a bit confused over what you mean by extending the macro to read the letters between the square brackets. You do have the text between the brackets available as #1, after all. You only need to use it in the body of your macro. – Harald Hanche-Olsen Oct 25 '10 at 20:13
@Harald Hanche-Olsen Thanks for the answer and the comment. If you try \elide[]{test} it works. I am trying to extend the macro so that one would be able to parse something like \elide[a,b,c]{} or \elide{}. I am also trying to understand the workings of \futurelet a bit better. – Yiannis Lazarides Oct 25 '10 at 20:19
Okay, but what do you want \elide[a,b,c]{} to do? – Harald Hanche-Olsen Oct 25 '10 at 20:37
@Harald Hanche-Olsen \elide[b,s]{text} -> [...]text (b=before,s=square brackets), \elide[a,b]{text}-> text[...], but primarily I am trying to relearn to program TeX/LaTeX, for an application I am building! \futurelet just tied my brain in knots:) – Yiannis Lazarides Oct 25 '10 at 20:59
Not really what you're trying to do. But for an example of an application of \futurelet see this question. – Juan A. Navarro Oct 25 '10 at 21:21
up vote 5 down vote accepted

If you are only trying to define a macro with an optional argument, \newcommand will do that for you:

  \else $\ldots$ #2\fi}

should work the same as your macro, except it may behave oddly if you give it an optional argument beginning with \relax.

share|improve this answer
This is a really bizarre use of an optional argument. The value is irrelevant. If this were the use case, I'd say go with a * instead. – TH. Oct 26 '10 at 2:40
Agreed. But assuming that I want to use the optional argument, in the case where it is present, and do something entirely different where it is not, this technique has worked well for me. – Harald Hanche-Olsen Oct 26 '10 at 10:06
@TH. of course, then \def\elide{\@ifnextchar*{<star-code>\@gobble}{<non-star-code>}} works just good (of course with \makeat(letter|other)). – yo' Aug 24 '12 at 22:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.