Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alright, then, here we go.</p> <p>As you can see below, the main part of the coding is parsing the comma separated range input. After that, it's easy to check what number you're up to in the enumerate environment (or whatever) and conditionally display the item.</p> <p>You can copy and paste from here on into an empty <code>.tex</code> document and it should just work:</p> <hr> <p>%% First of all, I'm using the expl3 package to do most of this coding. Makes some things easier.</p> <pre> \documentclass{article} \usepackage{expl3} \ExplSyntaxOn </pre> <p>%% Here's the function to loop over comma-list range input like <code>-2,4-6,8,10-</code>:</p> <pre> \prg_new_conditional:Nnn \i_in_range:nn {TF,T,F} { \bool_set_false:N \l_tmpa_bool \clist_map_inline:nn {#2} { \parse_range:w ##1 - \q_marker - \q_nil #1 \q_nil } \bool_if:NTF \l_tmpa_bool \prg_return_true: \prg_return_false: } </pre> <p>%% And the auxiliary function to return whether the input argument is contained within the range:</p> <pre><code>\cs_set:Npn \parse_range:w #1 - #2 - #3 \q_nil #4 \q_nil { \tl_if_eq:nnTF {\q_marker}{#2}{ \intexpr_compare:nT {#4=#1} {\bool_set_true:N \l_tmpa_bool} }{ \tl_if_empty:nTF {#2}{ \intexpr_compare:nT {#4&gt;=#1} {\bool_set_true:N \l_tmpa_bool} }{ \tl_if_empty:nTF {#1}{ \intexpr_compare:nT {#4&lt;=#2} {\bool_set_true:N \l_tmpa_bool} }{ \intexpr_compare:nT {#4&gt;=#1} { \intexpr_compare:nT {#4&lt;=#2} {\bool_set_true:N \l_tmpa_bool} } } } } } \cs_generate_variant:Nn \i_in_range:nnTF {nV} </code></pre> <p>%% This is the command to input each item of your list:</p> <pre> \newcommand\numitem[1]{ \i_in_range:nVTF {\value{enumi}+1}{\l_item_range_tl}{ \item #1 }{ \stepcounter{enumi} } } </pre> <p>%% And the enumerate environment with a range argument:</p> <pre> \newenvironment{someitems}[1]{ \tl_set:Nn \l_item_range_tl {#1} \begin{enumerate} }{ \end{enumerate} } \ExplSyntaxOff </pre> <p>%% Finally, an example:</p> <pre> \begin{document} \begin{someitems}{-2,4-6,8,10-} \numitem{one}\numitem{two}\numitem{three} \numitem{four}\numitem{five}\numitem{six} \numitem{seven}\numitem{eight}\numitem{nine} \numitem{ten}\numitem{eleven} \end{someitems} \end{document} </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload