Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphabetical lists #84

Closed
nopria opened this issue Jul 1, 2021 · 15 comments · Fixed by #168
Closed

Alphabetical lists #84

nopria opened this issue Jul 1, 2021 · 15 comments · Fixed by #168
Labels
feature request latex Related to the LaTeX interface and implementation lua Related to the Lua interface and implementation question syntax extension Related to syntax extensions and dialects of markdown

Comments

@nopria
Copy link

nopria commented Jul 1, 2021

I need to create an ordered list of type

a) first item
b) second item
c) third item

and since I did not find a way to do it in plain markdown, I tried with LaTeX enumerate environment, activating the hybrid option, but I get the error

! Undefined control sequence.
\enit@endenumerate ->\enit@after 
                                 \endlist \ifx \enit@series \relax \else \if...
l.31 ...f whitening the population \end{enumerate}
                                                  \markdownRendererInterbloc...

Is there a solution?

@Witiko Witiko added feature request latex Related to the LaTeX interface and implementation labels Jul 1, 2021
@Witiko
Copy link
Owner

Witiko commented Jul 1, 2021

Dear @nopria,

I need to create an ordered list of type a) first item b) second item c) third item

If you need all your ordered lists to be alphabetic, then you can restyle Markdown as follows:

\documentclass{article}
\usepackage{markdown, paralist}
\markdownSetup{
    startNumber = false,
    renderers = {
        olBegin = {\begin{enumerate}[a)]},
        olEnd = {\end{enumerate}}
    }
}
\begin{document}
\begin{markdown}
1. first item
2. second item
3. third item
\end{markdown}
\end{document}

This is in line with the philosophy that markdown does not contain presentation markup, only structural markup. The author types an ordered list between \begin and \end{markdown} and the designer decides which symbols to use for the individual items of the list in the \markdownSetup command.

I tried with LaTeX enumerate environment, activating the hybrid option, but I get the error Undefined control sequence. Is there a solution?

it is difficult to see what the cause of your error is without a minimal working example of your code.

@nopria
Copy link
Author

nopria commented Jul 1, 2021

If I need to alternate alphabetical with numbered lists how can I do?

About the error, it seems that just loading markdown package breaks enumitem and viceversa, here is a MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{markdown}

\begin{document}

\begin{enumerate}
\item first item
\item second item
\end{enumerate}

\end{document}

@Witiko
Copy link
Owner

Witiko commented Jul 1, 2021

it seems that just loading markdown package breaks enumitem and viceversa

The markdown package uses the paralist package to typeset tight lists. The paralist package likely collides with enumitem. You can set tightLists = false to disable tight lists. This will prevent the paralist package from being loaded.

If I need to alternate alphabetical with numbered lists how can I do [this]?

Not in Markdown (yet), since the appearance of lists is related to presentation, not content. As a general rule, markdown does not contain presentation markup. To change the presentation of your lists, you will need to use TeX.

\documentclass{article}
\usepackage[shortlabels]{enumitem}
\usepackage[startNumber = false, tightLists = false]{markdown}
\newcommand\alphabeticallists{%
    \markdownSetup{
        renderers = {
            olBegin = {\begin{enumerate}[a)]},
            olEnd = {\end{enumerate}}
        }
    }%
}
\newcommand\numberedlists{%
    \markdownSetup{
        renderers = {
            olBegin = {\begin{enumerate}[1.]},
            olEnd = {\end{enumerate}}
        }
    }%
}
\begin{document}
\begin{markdown*}{hybrid}

\alphabeticallists

The following list will be alphabetical:

1. first item
2. second item
3. third item

\numberedlists

The following list will be numbered:

1. first item
2. second item
3. third item

\end{markdown*}
\end{document}

If you would rather not use the hybrid mode:

% preamble omitted for brevity
\begin{document}
\alphabeticallists
\begin{markdown}

The following list will be alphabetical:

1. first item
2. second item
3. third item

\end{markdown}
\numberedlists
\begin{markdown}

The following list will be numbered:

1. first item
2. second item
3. third item

\end{markdown}
\end{document}

Does this help you solve your issue?

@nopria
Copy link
Author

nopria commented Jul 2, 2021

Yes, this solution suits nicely my need.

Just one last question. Why an enumerate environment added inside markdown environment in hybrid mode is completely ignored?

@Witiko
Copy link
Owner

Witiko commented Jul 2, 2021

Just one last question. Why an enumerate environment added inside markdown environment in hybrid mode is completely ignored?

It should not be ignored. You can debug this by taking a look at the TeX documents produced in the _markdown_(name of your document) dictionary. These are what is actually typeset by LaTeX. The conversion from Markdown to TeX removes newlines, perhaps the enumitem package does not like that? Difficult to tell without an MWE.

@nopria
Copy link
Author

nopria commented Jul 2, 2021

I found out that it was ignored because of a commented line (%) just before \begin{enumerate}, so forget my report but maybe this revealed an unwanted behavior.

@Witiko
Copy link
Owner

Witiko commented Jul 2, 2021

Yes, since the conversion from Markdown to TeX does not obey newlines, this introduces the non-intuitive behavior, where TeX comments consume more than one line of your markdown input. This non-intuitive behavior has been fixed in v2.10.0, which I'm planning to release by TUG 2021 this August, but which you can try out by using the version from this repository: comments are now disabled in hybrid mode (% will be typeset as %), but you can enable the texComments option, which adds proper support for TeX comments on the side of Markdown (there is a lexical preprocessor, which strips them before the conversion from Markdown to TeX), see also my monologues on the matter in #42 (comment).

@nopria
Copy link
Author

nopria commented Jul 5, 2021

It seems that a simple macro can replace all the macros possibly needed to render custom ordered lists. The following macro lets the user define "on the fly" the type of list, using the options of enumitem (or other) package:

\newcommand\mdlists[1]{%
    \markdownSetup{
        renderers = {
            olBegin = {\begin{enumerate}#1},
            olEnd = {\end{enumerate}}
        }
    }%
}

So, for example, alphabeticallists can be replaced by \mdlists{[a)]} or \mdlists{[a),noitemsep]} if you want a compact list.

With just one macro the user can take advantage of the versatility and power of LaTeX ordered lists. I think that's wonderful.

@Witiko
Copy link
Owner

Witiko commented Jul 5, 2021

Thank you. The ability to easily change the design of markdown elements on the fly is one of the unique features of this package.

@nopria
Copy link
Author

nopria commented Jul 17, 2021

I didn't pay attention to the startNumber = false option setting till now, but now that I need startNumber = true I see that the above solutions do not work, that is the ordered list style remains the standard one 1. 2. 3.

Is there a solution working with startNumber = true too?

@Witiko
Copy link
Owner

Witiko commented Jul 17, 2021

You can redefine the olItemWithNumber renderer and transform the number to the desired format:

\markdownSetup{
    renderers = {
        olItemWithNumber = {\item[\romannumeral#1\relax)]},
    }
}

example output

However, this makes it difficult to use the enumitem package. You could go with startNumber = false and use \mdlists{[resume]} when you need to continue a numbered list:

1. One
2. Two

\mdlists{[resume]}

3. Three
4. Four

example output

@nopria
Copy link
Author

nopria commented Jul 17, 2021

Thanks, \mdlists{[resume]} is fine. Another option is \setlist[enumerate]{resume}, which might be more convenient when using a custom ordered list because you don't have to repeat the custom list definition.

@Witiko
Copy link
Owner

Witiko commented Jul 18, 2021

Definitely. There are many ways to achieve what you want.

@Witiko Witiko added the lua Related to the Lua interface and implementation label Aug 8, 2021
@Witiko Witiko added the syntax extension Related to syntax extensions and dialects of markdown label Sep 2, 2021
@nbubis
Copy link

nbubis commented Oct 23, 2021

Would there be any way to auto-magically detect the enumeration of the list?

As in, one could add both numbered and alphabetical lists to a markdown document without the use of any in-document latex commands, and have the latex package correctly format them both? This would be inline with what the folks at pandoc are doing:

Unlike standard Markdown, pandoc allows ordered list items to be marked with uppercase and lowercase letters and roman numerals, in addition to Arabic numerals. List markers may be enclosed in parentheses or followed by a single right-parentheses or period. They must be separated from the text that follows by at least one space, and, if the list marker is a capital letter with a period, by at least two spaces.


The following list will be alphabetical:

a. first item
b. second item
c. third item

The following list will be numbered:

1. first item
2. second item
3. third item

@Witiko
Copy link
Owner

Witiko commented Oct 23, 2021

@nbubis It is not difficult to implement (the basic version of) this, but the philosophy of markdown is one of separation of presentation from content. In the words of Michael Thompson from the pandoc-discuss mailing list:

The paucity of means is the greatest virtue of markdown [...].

It is strangely difficult to get people to see the point, but the defects of LaTeX for concentration, writing and thought, are at least as great as those of Word, for the simple reason that it gives the writer too much power; there is always another package to call in the preamble, as there is always another drop down menu in Word. [...]

In markdown - not to put too fine a point on it - the writer is only ever faced with one question, and it is the right one: what the next sentence should be.

I am not convinced that the choice between alphabetical and numbered lists is not related to presentation and should lie with the writer rather than the design person.

Repository owner locked and limited conversation to collaborators Oct 23, 2021
@Witiko Witiko closed this as completed Oct 23, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
feature request latex Related to the LaTeX interface and implementation lua Related to the Lua interface and implementation question syntax extension Related to syntax extensions and dialects of markdown
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants