I would like to underline even items or odd items in itemize environment. Is there a more convenient way than:

\item \uu{some text}
\item some text
\item \uu{some text}
\item some text
\item \uu{some text}
\item some text
  • 1
    I think it would come at the cost of needing to wrap each entry in a macro ... so that probably isn't 'saving' you anything: not typing, and therefore certainly not time. (One obvious exception would be to use a font that is underlined by default and switch to and from that.) – jon Sep 30 '16 at 3:28
  • I agree with @jon. The problem is underline, not parity. See tex.stackexchange.com/questions/198484/… – Symbol 1 Sep 30 '16 at 4:17

Note that \item has be redefined to treat the text as an argument. Also this only supports one level.


\newcommand{\myitem}[1]% text must be placed in braces


\item{odd text}
\item{even text}




You can split the contents of an environment at every occurrence of \item which allows you to separate out the "arguments" for every list item. That way you can perform an action (conditionally) on an \item:

enter image description here


% https://tex.stackexchange.com/a/127014/5764

  \int_zero:N \l_odd_even
  \keys_set:nn { oddeven/itemize } { #1 }
  \seq_set_split:NnV \l_oddeven_itemize_input_seq { \item } \BODY
  \seq_pop_left:NN \l_oddeven_itemize_input_seq \l_tmpa_tl
  \tl_use:N \l_oddeven_itemize_pre_tl
    { \exp_not:n { \__oddeven_itemize_do:n { ##1 } } }
  \seq_use:NV \l_oddeven_itemize_output_seq \l_oddeven_itemize_sep_tl
  \tl_use:N \l_oddeven_itemize_post_tl

\seq_new:N \l_oddeven_itemize_input_seq
\seq_new:N \l_oddeven_itemize_output_seq
\cs_generate_variant:Nn \seq_set_split:Nnn { NnV }
\cs_generate_variant:Nn \seq_use:Nn { NV }
\int_new:N \l_odd_even

\keys_define:nn { oddeven/itemize }
  pre  .tl_set:N = \l_oddeven_itemize_pre_tl,
  post .tl_set:N = \l_oddeven_itemize_post_tl,
  sep  .tl_set:N = \l_oddeven_itemize_sep_tl,
  action .code:n = \cs_set_eq:NN \__oddeven_itemize_do:n #1,
  action .initial:n = \use:n,

  \item #1
  \int_incr:N \l_odd_even
  \int_if_odd:nTF { \l_odd_even }
    {\ul{#1}}% Underline odd
    {#1}% Do nothing for even
  \int_incr:N \l_odd_even
  \int_if_odd:nTF { \l_odd_even }
    {#1}% Do nothing for odd
    {\ul{#1}}% Underline even


  \item First
  \item Second
  \item Third
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Sed semper eros sed quam ullamcorper iaculis tincidunt feugiat neque. 
    Donec ut risus at arcu tristique porttitor. Proin sollicitudin 
    sollicitudin aliquam. Mauris rutrum, erat et gravida ornare, odio 
    justo aliquet ipsum, at venenatis sem quam fermentum tortor. 
  \item Integer et ante non libero scelerisque hendrerit at nec dui. 
    Proin ante velit, finibus id tempor id, laoreet eu quam. 
    Suspendisse semper ex id magna luctus egestas. 
    Phasellus pharetra nibh bibendum felis commodo pulvinar.
  \item Last


The items are formatted using an action. In the above example, we use \underlineodd, but you can switch this to \underlineeven to underline even-numbered \items.

Underlining is done with support from soul to allow for line-breaks.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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