1

I tried to define the shortcuts

\documentclass{article}

\usepackage{tasks}

\def\bqcmt{\begin{tasks}(2)}
\def\eqcmt{\end{tasks}}
\def\myitem{\task}

\begin{document}
\bqcmt
\myitem This is a test
\eqcmt
\end{document}

But it does not work. The error is:

LaTeX Error: \begin{tasks} on input line 10 ended by \end {document}.

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

                                               l.13 \end{document}

Why is it so? How can I define such shorcuts?

A solution ?

The following seems to work

\documentclass{article}
\usepackage{tasks}

\def\bqcmt{\csname tasks\endcsname(3)}
\def\eqcmt{\endtasks}
\def\myitem{\csname endtasks\endcsname}

\begin{document}
\bqcmt
\task This is a test
\task This is a test
\task This is a test
\eqcmt
\end{document}

as well as

\documentclass{article}
\usepackage{tasks}

\newcommand{\bqcmt}[1]{\csname tasks\endcsname(#1)}
\def\eqcmt{\endtasks}
\def\myitem{\csname endtasks\endcsname}

\begin{document}
\bqcmt{3}
\task This is a test
\task This is a test
\task This is a test
\eqcmt
\end{document}

My new question ?

But I'm wondering if it is a good idea. Indeed, \begin{tasks} will normally scan the rest of the file for an \end{tasks}. With this "hack", I guess that this scan will not happen.

11
  • 4
    Never do you, you even up with a poor sematics and code that is hard to read. Instead look into the features of your editor. Most editors today have the ability to insert small templates at a press of a button, thus one key stroke and you have all this written for you
    – daleif
    Aug 24, 2018 at 13:36
  • 1
    Then please explain those reasons? And why an inferior syntax is better? You will see it again and again here that we never recommend doing this. BTW did you try the standard trick of using the macro form of the environment? aka \tasks{2} and \endtasks (untested)
    – daleif
    Aug 24, 2018 at 14:01
  • 1
    The TeX engine doesn't know what an environment is. It simply expands macros. IIRC, \begin is simply \csname #1\endcsname and \end is \csname end#1\endcsname. Aug 24, 2018 at 14:37
  • 1
    \begin only uses \csname because the name is passed as an argument. \tasks is fine. Aug 24, 2018 at 15:47
  • 2
    Could you say a few words why you added a bounty to this question? Your edits already seem to solve your problem
    – siracusa
    Aug 27, 2018 at 19:27

1 Answer 1

2
+50

It's a bad idea.

Anyway, you can use a macro with delimited argument.

\documentclass{article}
\usepackage{tasks}

\long\def\bqcmt#1#2\eqcmt{\begin{tasks}(#1)#2\end{tasks}}

\begin{document}

\bqcmt{3}
\task a
\task b
\task c
\task d
\task e
\task f
\eqcmt

\bigskip

\begin{tasks}(3)
\task a
\task b
\task c
\task d
\task e
\task f
\end{tasks}

\end{document}

enter image description here

You can define a “new task” for using \item as a separator.

\documentclass{article}
\usepackage{tasks}

\NewTasks{colastasks}[\item]

\long\def\bqcmt#1#2\eqcmt{\begin{colastasks}(#1)#2\end{colastasks}}

\begin{document}

\bqcmt{3}
\item a
\item b
\item c
\item d
\item e
\item f
\eqcmt

\end{document}
3
  • Thanks for your answer. Is it also possible to redefine \task to \myitem or, better, to \item? Thanks
    – Colas
    Aug 28, 2018 at 10:04
  • @Colas It just takes reading the manual.
    – egreg
    Aug 28, 2018 at 10:18
  • Thanks @egreg. I tried various ways to define "\item=\task" but didn't think of reading the manual. Thanks a lot !
    – Colas
    Aug 28, 2018 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .