6

I've installed the easylist package and am using it just fine. I've tried to create a custom command to shorten my typing as I've done before with the regular \begin{itemize}.

My regular one that works is:

\newcommand{\itml}[1]{\begin{itemize} #1 \end{itemize}}

I use like this:

\itml{
    \item first item
    \item second item
}

The one that does not work:

\newcommand{\el}[1]{\begin{easylist}[itemize] #1 \end{easylist}}

When used as:

\el{
    # first item
    ## second item
}

I get the following error:

! You can't use `macro parameter character #' in vertical mode.
<argument>  ##
           first item #### Second item
l.44 }

What actually does work is:

\newcommand{\bel}{\begin{easylist}[itemize]}
\newcommand{\eel}{\end{easylist}}

When used as:

\bel
    # first item
    ## second item
\eel

Basically, I don't want to type the closing tag?

UPDATE: I have all of my custom commands in a separate file like so:

% commands.tex file
\newcommand{\avgE}{\bar{E}}

...

\newcommand{\bel}{\begin{easylist}[itemize]}
\newcommand{\eel}{\end{easylist}}
\newcommand{\el@aux}[1]{\begin{easylist}[itemize] #1 \end{easylist}\endgroup}
\newcommand{\el}{\begingroup\Activate\el@aux}
\newcommand{\bl}[1]{\bel #1 \eel}
\newcommand{\itml}[1]{\begin{itemize} #1 \end{itemize}}

And in my regular files, I say:

% regular latex file
\documentclass[11pt,letterpaper]{article}
...
\input{../src/commands.tex}
....

When trying it in my regular file I get the following error:

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.25 ...list}[itemize] #1 \end{easylist}\endgroup}

Does that mean I have to declare these custom commands in each "regular" file and cant put it in just one place for all files?

lockstep
  • 250,273
Diego
  • 233
  • So you've found a workaround using an environment type definition. Is your question that you want the macro type solution to work as well? – Werner Jun 18 '13 at 00:34
  • Not sure what the difference is between them. Basically what I want is to not type a closing tag – Diego Jun 18 '13 at 00:53
  • When you have a macro-form of something, the argument is read at the current catcodes. So, when passing the argument to be used within an environment (similar to your \el{..} definition), the modification of catcodes by easylist no longer has an effect. Within the environment-form, no argument is gobbled and therefore the output works... – Werner Jun 18 '13 at 00:58
  • I see. So due to the way easylist works, I'd have to go with \bel solution as opposed to the \el solution? If so, you can answer the question and I'll accept! – Diego Jun 18 '13 at 01:02

1 Answers1

4

Here's a way to get what you want - locally updating the category code of # before reading the macro argument. easylist provides this functionality through \Activate (and a companion \Deactivate) that updates the category code of the required "item character":

enter image description here

\documentclass{article}
\usepackage[sharp]{easylist}% http://ctan.org/pkg/easylist

% Environment-style definitions
\newcommand{\bel}{\begin{easylist}[itemize]}
\newcommand{\eel}{\end{easylist}}

% Macro-style definitions
\makeatletter
\newcommand{\el@aux}[1]{\begin{easylist}[itemize] #1 \end{easylist}\endgroup}
\newcommand{\el}{\begingroup\Activate\el@aux}
\makeatletter
\begin{document}

\el{
  # first item
  ## second item
}

\bel
  # first item
  ## second item
\eel
\end{document}

Local updating is ensured using a \begingroup...\endgroup clause (and therefore there is technically no need for a "closing" \Deactivate). \el actually only starts the process, while \el@aux is the actual macro that gobbles the argument to be passed to easylist.

Some references, for relevance:

Werner
  • 603,163