1

Here's an example:

\documentclass{article}

\usepackage[sharp]{easylist} % use # symbol to denote a list
\usepackage{minted}

\begin{document}

\begin{easylist}[enumerate]
# Profile Python
\begin{minted}{python}
import math
\end{minted}
\end{easylist}

\end{document}

To make it work, I could just use other symbols like \usepackage[at]{easylist} instead of sharp. But I am curious because error message cannn't really tell me why is this not working. Do someone know the why I cannot use #?

The error message is:

_./main.out.pyg:2:
Use of \FV@PYG doesn't match its definition.
\PYG #1#2->\FV@PYG {
                #1}{\FancyVerbBreakStart #2\FancyVerbBreakStop }
l.2 \PYG{k+kn}{import} \PYG{n+nn}{math}

Update:

Please see @egreg's answer below (and comments!) for an explanation.

A solution to the above question using \Activate and \Deactivate command provided by easylist.:

\documentclass{article}

\usepackage[sharp]{easylist} % use # symbol to denote a list
\usepackage[cache=false]{minted}
\title{useless}
\begin{document}

\begin{easylist}[enumerate]
# Deactivate it first,
\Deactivate
\begin{minted}{python}
import math
\end{minted}
\Activate
# then activate it again.
# Good!
\end{easylist}

\end{document}
taper
  • 293
  • Does it make sense to use minted inside easylist to begin with? – egreg Feb 16 '18 at 18:41
  • I think yes. Because if I use a different symbol, there would be no problem. Also, a vague analogy is that since verbatim works in easylist, why not minted? @egreg – taper Feb 16 '18 at 19:03
  • Possibly the answer is that the symbol # is used in minted. And since minted is loaded in easylist, easylist adjust what # means and this clashes with minted. So the choice would only be use another symbol for easylist. – taper Feb 16 '18 at 19:14

1 Answers1

1

The sharp option makes # into an active character. The files that are produced by pygmentize contain macro definitions which in turn use # and, because of being inside easylist, this character is no longer the parameter specifier.

Thus all the auxiliary macros with argument that minted needs to use don't work as expected.

Using other characters can lead to other problems; I tried the at option and @ won't work in minted. For example

\documentclass{article}

\usepackage[at]{easylist} % use # symbol to denote a list
\usepackage{minted}

\begin{document}

\begin{easylist}[enumerate]
@ Profile Python
\begin{minted}{python}
    @classmethod
\end{minted}
\end{easylist}

\end{document}

will not print @.

Besides, minted will not respect the current indentation in the list.

Here's a comparison:

\documentclass{article}

\usepackage{easylist}
\usepackage{minted}

\begin{document}

\begin{enumerate}
\item Profile Python
\begin{minted}{python}
# This program prints Hello, world!
print('Hello, world!')
\end{minted}
\begin{enumerate}
\item Indented
\begin{minted}{python}
# This program prints Hello, world!
print('Hello, world!')
\end{minted}
\end{enumerate}
\end{enumerate}

\begin{easylist}[enumerate]
§ Profile Python
\begin{minted}{python}
# This program prints Hello, world!
print('Hello, world!')
\end{minted}
§§ Indented
\begin{minted}{python}
# This program prints Hello, world!
print('Hello, world!')
\end{minted}
\end{easylist}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Good explanation! It's strange that @ does not work for you though. – taper Feb 16 '18 at 21:45
  • 1
    @taper Try @classmethod in the Python code. The @ will disappear. I added a full example. – egreg Feb 16 '18 at 21:58
  • Oh.. Sure. Then I found, among documented keywords, § to be a fairly good choice. Since it is rarely used, could be inputed by \S when needed, and is available on my keyboard (:P). – taper Feb 16 '18 at 22:11
  • Hi @egreg, I just found in easylist's documentation there is a way to circumvent this problem. It is updated in my question. – taper Feb 16 '18 at 22:25
  • @taper And now, where’s the advantage over using a regular \item? – egreg Feb 16 '18 at 22:29
  • Because I usually want multiply indented ones, like those popular in Word/OneNote (called Harvard style in Pages). And it is a terrible experience to work with multiple \begin{enumerate} \item \begin{enumerate} \item \begin{...} OMG \end.... Whereas in easylist, this task is super easy. – taper Feb 16 '18 at 22:47
  • @taper With the non negligible disadvantage that minted does not follow the indentation of the list, whereas it does with enumerate. – egreg Feb 16 '18 at 22:52
  • @taper I added a visual comparison. – egreg Feb 16 '18 at 22:58
  • Good illustration. I think we could think of easylist as one best in writing quick notes (as is actually what I want to achieve with it), where I do not care too much about the indentation and look, but care very much about convenience. But in you case, it would certainly be more appropriate to use enumerate. – taper Feb 16 '18 at 23:01