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

this is my first question, so any help is appreciated.

I want to achieve an indentation effect as shown in the image:

itemize approach

Which can be obtained as follows:

  \item $a$
    \item $b1$
    \item $b2$
  \item $c$

The point is that I want to create an xparse \DocumentCommand that receives the item arguments without $ signs and separated by the . character and recreates the previous itemize structure.

For example, lets say the named function is called \tab. Then,


should give the same result as above.

Hope you understand what I'm looking for.

Edit: Finally got it thanks to \@ifnextchar:

\def\test{\@ifnextchar\tab{\relax}{\item $}}
\newcommand{\entry}[1]{\test#1 \ifmmode $ \fi }

Thanks for your help.

share|improve this question
Welcome to TeX.SX! – Adam Liter Apr 10 '14 at 19:14
I think I have resolved the math mode issue. – Steven B. Segletes Apr 10 '14 at 20:20
up vote 2 down vote accepted

With just xparse it's too complicated. Using \@ifnextchar is possible, but a jump to expl3 is perhaps better:


  % start an itemize (that also provides grouping for nested calls)
  \azpillaga_tab:n { #1 }
  % finish off

\seq_new:N \l__azpillaga_tab_input_seq

\cs_new_protected:Npn \azpillaga_tab:n #1
  % split the input into components at the periods
  \seq_set_split:Nnn \l__azpillaga_tab_input_seq { . } { #1 }
  % process one item at a time
  \seq_map_inline:Nn \l__azpillaga_tab_input_seq
    % check if the item starts with \tab
    \peek_meaning:NF \tab
     {% it doesn't: add \item and $
      \item $
    % the item
    % add $ if in \item
    \mode_if_math:T { $ }




enter image description here

share|improve this answer

Here I make the . active inside \tab and restore it when I am done. Inside \tab, the . can become \item if the next token is a not a nested \tab and it becomes \relax if the next token is a nested \tab. I keep track of the nesting level with a simple counter, and only restore the catcode 12 definition of . when the nesting level reaches back to zero.

I have EDITED to allow switching between text mode and math mode processing.

In my RE-EDIT, I have resolved the issue of the stray $$ lines which popped up in math mode (requiring a countermanding \vspace), so that no \vspaces are presently required, and the spacing in math mode matches that of a true itemize environment.

In my MWE, I have placed text and math versions side-by-side in minipages for comparison.

    \item\DOL#1\if F\tabdone\DOL\fi\gdef\tabdone{T}%
\def\dotparse{\if F\tabdone\DOL\fi\def\tabdone{F}\@ifnextchar\tab\relax\xitem}
\parskip 1em

enter image description here

I would add in passing that, as is, the OP has prohibited the use of the dot as part of his argument, since his requested syntax will interpret the . as a call for a new \item or nested itemize. If one really does need a dot as part of the data stream, it would make sense to choose a different character than . as the parsing separator, which is easy enough to accomplish by way of substitution in the MWE.

share|improve this answer
The extra lines issue is the actual reason that caused me to make this question. You made a hard work but the problem isn't still totally solved. If you make a 4 nestlevel call, such as \tab{a.\tab{b1.\tab{b11.\tab{b112.b113}}.b2}.c.\tab{1.2}.d} the linebreaking fails. Any possible workaround? I appreciate your effort. – Martin Azpillaga Apr 10 '14 at 20:36
@MartinAzpillaga After a bit of struggle, the problem is resolved in math mode, as now shown in my MWE. – Steven B. Segletes Apr 11 '14 at 13:10

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.