1

This is a follow-up question to Enumitem \SetEnumitemKey and conflict between multiple key before and after.

I want to use a key value in a list in the definition of another. Here I use a better definition of \Pointilles which allows a second parameter, i.e. the vertical space between the dots.

So I put this code instead of the old one:

\usepackage{xargs}  
\newcommand{\auxpts}[1]{\makebox[\linewidth]{\dotfill} #1}
% Pointilles
\newcommandx{\Pointilles}[2][1=1,2=\bigbreak]{%
    \vspace*{-\medskipamount}
    \multido{\i=1+1}{#1}{%
        \auxpts{#2}
    }
}

and replace each occurrence of \Pointilles{#1} by \Pointilles[#1], and \Pointilles{2} by \Pointilles[2].

This gives the final code:

\documentclass[twocolumn]{article}
\usepackage[a4paper, top=0.5cm, bottom=1.6cm, left=0.7cm , right=0.7cm]{geometry}
\parindent0cm
\usepackage{multido}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{xargs}

\newcommand{\auxpts}[1]{\makebox[\linewidth]{\dotfill} #1}
% Pointilles
\newcommandx{\Pointilles}[2][1=1,2=\bigbreak]{%
    \vspace*{-\medskipamount}
    \multido{\i=1+1}{#1}{%
        \auxpts{#2}
    }
}

\newlist{innanswers}{enumerate}{1}
\setlist[innanswers]{
  label=\arabic*.,
  before=\maybemulticols\maybedots,
  after=\maybefinaldots\maybeendmulticols
}
\newenvironment{answers}[1][]
 {\setkeys{m45}{#1}\innanswers}
 {\endinnanswers}

\let\maybemulticols=\relax
\let\maybeendmulticols=\relax
\let\maybedots=\relax
\let\maybefinaldots=\relax
\def\doitemdots#1{%
  \let\olditem\item% save the standard definition of \item in a macro, \olditem
  \firstItemtrue% set the toggle for first item in the list to true
  \def\item{%
    \iffirstItem
      \olditem\firstItemfalse
    \else
      \newline\Pointilles[#1][\bigbreak]\mbox{}\olditem %TODO here need to replace \bigbreak by the value of a parameter
   \fi
  }% new, temporary defition of \item
}
\def\dofinaldots#1{%
  \ \newline \Pointilles[#1][\bigbreak]\mbox{} %TODO here need to replace \bigbreak by the value of a parameter
}

\makeatletter
\define@key{m45}{cols}{%
  \def\maybemulticols{\begin{multicols}{#1}}%
  \def\maybeendmulticols{\end{multicols}}%
}
\newif\iffirstItem\firstItemfalse

\define@key{m45}{dots}{%
  \def\maybedots{\doitemdots{#1}}
  \def\maybefinaldots{\dofinaldots{#1}}
}
\makeatother
%==========================================
\begin{document}

\Pointilles[2]
\hrule
\begin{answers}[cols=4]
    \item first
    \item second
    \item third
    \item fourth
\end{answers}
\hrule
\begin{answers}[dots=2]
    \item first
    \item second
    \item third
    \item fourth
\end{answers}
\hrule
\begin{answers}[cols=2, dots=2]
    \item first
    \item second
    \item third
    \item fourth
\end{answers}
\hrule
\begin{answers}[dots=2, cols=2]
    \item first
    \item second
    \item third
    \item fourth
\end{answers}
\hrule
\end{document}

So the question is: how can I do to pass a new key value in the list instead of the default \bigbreak (the two matching lines have a %TODO)?

Your Answer

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

Browse other questions tagged or ask your own question.