Skip to content
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

Indentation sub-mode for moodle.sty documents #2020

Closed
Rmano opened this issue Apr 6, 2021 · 6 comments
Closed

Indentation sub-mode for moodle.sty documents #2020

Rmano opened this issue Apr 6, 2021 · 6 comments

Comments

@Rmano
Copy link

Rmano commented Apr 6, 2021

This is a very low priority indentation request. The objective is to support moodle.sty, a package used to prepare tests and quizzes that can be automatically added to the online-teaching platform Moodle.

Basically, there are two types of environments. The first one is a simple

\begin{quiz}[options]{Title/with/slashes}
\end{quiz}

into which all the other environments are to be embedded, and can be used as a flag to activate all the other environments. I would probably prefer NOT to indent its content, as it happens for document, because it can be only top-level.

The other environments are mostly of the form:

\begin{type}[options]{Title}
  Description, one or more paragraphs with a restricted set of commands and environments,

  \[formulas\] and maybe also pictures (both `includegraphics` and `tikzpictures`).

  \item [options] blah blah
  \item * the star is the correct one
  \item etcetera
\end{type}

where type can be one of multi, essay, truefalse, numerical, shortanswer, matching.

As an exception, the environment cloze has the same general structure, but instead of enclosing directly the \items, it allows for nested multi, numerical or shortanswer but without the {Title} argument.

\begin{cloze}{Cloze}
  Question text

  More paragraphs of question text

  \[ formula \]

  \begin{tikzpicture}[scale=0.5]
    \draw (0,0) -- (1,1);
  \end{tikzpicture}

  \begin{multi}[horizontal,shuffle=false]
    Question text

    \item[feedback={AAA}]* A
    \item[feedback={BBB},fraction=10] B
    \item[feedback={CCC}] C
  \end{multi}

  \begin{shortanswer}[tolerance=1]
    Question text
    \item[feedback={1}] aaa
    \item[feedback={3},fraction=0] bbb
  \end{shortanswer}
\end{cloze}

Finally, inside quiz, the description environment is redefined as

\begin{description}{Title}
  Description text
\end{description}

I add a file here with an example of (in my opinion!) a well-indented document and the current indentation:

moodle_examples_indents.zip

One possible solution is to have a kind of "extended" itemize-type environment that can accept a first paragraph that is not \item-ized.

@lervag
Copy link
Owner

lervag commented Apr 6, 2021

From all of this, I find your last sentence quite covering:

One possible solution is to have a kind of "extended" itemize-type environment that can accept a first paragraph that is not \item-ized.

That is, to allow a special itemize type environment like this:

\begin{env}[opts]
  Initial text
  \item's
\end{env}

This is not possible currently, as all itemize type environments assumes the first element is an \item. Thus, one solution is to add an option like let g:vimtex_indent_lists_with_intro = ['envs']. I don't like that option name, though, so feel free to suggest a better name.

Alternatively: I could change the current itemize indent to allow an initial text, then you could simply add to the existing g:vimtex_indent_lists option. It is perhaps simpler, but also feels a little bit more "hacky".

@Rmano
Copy link
Author

Rmano commented Apr 7, 2021

This is not possible currently, as all itemize type environments assumes the first element is an \item. Thus, one solution is to add an option like let g:vimtex_indent_lists_with_intro = ['envs']. I don't like that option name, though, so feel free to suggest a better name.

Yes, this is a quite nice possibility --- but the pattern should be

\begin{env}[opts]{optional braced argument}
  Initial text
  \item's
\end{env}

and the name... well... g:vimtex_indent_mixed_par_lists? (I am very bad for names).

The alternate possibility sound good too, if it accepts the possible argument.

As an aside: I just notice that

\begin{itemize}
    \item uno
    \item due
    \item tre 

        quattro

        cinque
    \item sei
\end{itemize}

is indented with the extra paragraphs in the \item like above... is that expected? Maybe it would be better to align the paragraph under the first char of the item above? (Yes, I am going off topic a bit).

@lervag
Copy link
Owner

lervag commented Apr 7, 2021

This is not possible currently, as all itemize type environments assumes the first element is an \item. Thus, one solution is to add an option like let g:vimtex_indent_lists_with_intro = ['envs']. I don't like that option name, though, so feel free to suggest a better name.

Yes, this is a quite nice possibility --- but the pattern should be ...

Great. I'll look into this when I get the time. I'll start by making it optional in a separate branch, then consider to merge it with default behaviour before merging.

As an aside: I just notice that ...
is indented with the extra paragraphs in the \item like above... is that expected? Maybe it would be better to align the paragraph under the first char of the item above? (Yes, I am going off topic a bit).

Yes it is expected. And yes, in a way I agree that aligning on the first character would look good, but it becomes much harder to achieve. The current behaviour is to always work with adding or removing indents based on &shiftwidth. Thus, we only need to track whether or not to remove or add indents. Your suggestions adds two complications:

  1. We need to keep track of the amount of indentation. That is, after the first \item ... indented paragraphs, the next \item must be de-indented the right amount of white space. Thus, it would require more state data, and this makes everything less robust and more complicated.

  2. Some people prefer to use tabs; how would or should that work? With the current method, we always just add or remove one level of indentation, and things will work the same regardless of the users whitespace/tab preference. I.e., we would need to define the proper behaviour, and then adding support for it would mean more complications and possibilities for bugs.

Personally, I very much agree that VimTeX indentation is quite far from ideal. Your current example is just one of many cases where I think the indentation could look better. But when I was working on these things, I realized it was very hard to make it work reliable when I tried to be "fancy", so I decided to be pragmatic and instead make it just good enough to be useful.

@Rmano
Copy link
Author

Rmano commented Apr 7, 2021

Personally, I very much agree that VimTeX indentation is quite far from ideal. Your current example is just one of many cases where I think the indentation could look better. But when I was working on these things, I realized it was very hard to make it work reliable when I tried to be "fancy", so I decided to be pragmatic and instead make it just good enough to be useful.

100% agree

@lervag
Copy link
Owner

lervag commented Oct 6, 2021

Sorry about the large delay here; I've pushed a minor update that simply avoids the deindent on the first \item. I believe it should resolve your issue. Please test.

lervag added a commit that referenced this issue Oct 6, 2021
@lervag lervag closed this as completed Oct 6, 2021
@Rmano
Copy link
Author

Rmano commented Oct 7, 2021

Tested, works ok!
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants