#99 latex2e: Handle classes for bullet & field lists

None
closed-fixed
nobody
None
5
2017-05-05
2012-11-15
No

latex2e: Handle classes for bullet lists

For example authors could customize documents as follows:

.. class:: compact

- item 1
- item 2
- item 3

and expect the writer to apply the class. This works for html writer,
but not yet for latex2e/xetex and that's why this patch is here.

Usual rules for customizing rendering for classed elements is done - for
class `compact`, if stylesheet provides an environment named
DUitemizecompact, it will be used, otherwise the default itemize.

Personally, for compact lists I use

\newenvironment{DUitemizecompact}{%
\begingroup%
\small%
\begin{itemize}%
\itemsep=0pt\parskip=0pt%
}{%
\end{itemize}%
\endgroup%
}

which make text a bit smaller and tightens inter-line gaps.

NOTES:

* There is no \provideenvironment in LaTeX, so plain \newenviroment is used.
* The implementation of DUitemize environment is a bit cumbersome.
That's because it is not possible to pass arguments to
end<something> when defining environments and because my TeX foo is
probably not high enough. (help appreciated)
* I've patched the code to emit \begin{DUitemize} only when classes
attrubute is present - only to minimize changes to tests, for the
patch not being huge with low signal/noise ratio.

Discussion

  • Kirill Smelkov

    Kirill Smelkov - 2012-11-15

    NOTE: The TeX part of the patch (DUitemize environmet) probably needs polish, but if otherwise in general this approach is correct, I'd like to add more class handling to latex2e backend - for example to field lists and other environments.

    Thanks beforehand for your reply,
    Kirill

     
  • Kirill Smelkov

    Kirill Smelkov - 2012-11-15

    Simplified TeX preamble:

    PreambleCmds.itemize = r"""
    % bullet list
    \newenvironment{DUitemize}[1][class-arg]{%
    % store #1 for end
    \begingroup%
    \def\DUitemizearg{#1}%
    %
    \ifcsname DUitemize#1\endcsname%
    %\begin{DUitemize#1}% XXX why this does not work?
    \begin{DUitemize\DUitemizearg}%
    \else%
    \begin{itemize}%
    \fi%
    }{%
    \ifcsname endDUitemize\DUitemizearg\endcsname%
    \end{DUitemize\DUitemizearg}%
    \else%
    \end{itemize}%
    \fi%
    \endgroup%
    }%
    """

     
  • Kirill Smelkov

    Kirill Smelkov - 2012-11-20

    Uploaded cleaned up patch and demo.

     
  • Kirill Smelkov

    Kirill Smelkov - 2012-11-28
    • summary: latex2e: Handle classes for bullet lists --> latex2e: Handle classes for bullet & field lists
     
  • Günter Milde

    Günter Milde - 2017-02-08

    I don't like the idea of local commands/environments just for class handling.
    Instead, I propose wrapping elements in a group or environment if there are class arguments present. Standard environments could then be easily redefined in preamble, stylesheet, or raw latex code.
    The attached patch is a first suggestion (variant with class declarations in an anonymous group)

     
    Last edit: Günter Milde 2017-02-08
    • Matej Cepl

      Matej Cepl - 2017-02-10

      Yes, it builds (with its testsuite switched on) for Fedora. Thank you.

       
  • Günter Milde

    Günter Milde - 2017-02-08

    Generated LaTeX source (make sure to specify the required package(s), especially enumitem when generating from the above rST).

     
  • Günter Milde

    Günter Milde - 2017-02-08

    The alternative suggestion uses class declarations or class environments in a wrapper
    \begin{DUclass} \end{DUclass} environment.

    +1 simpler definition of post-element code (end part of environment)

    -\newcommand*{\DUCLASSrulebelow}{%
    -  \let\OrigItemize\itemize
    -  \renewenvironment{itemize}{\begin{OrigItemize}}%
    -                            {\end{OrigItemize}\noindent
    -                             \rule[0.5ex]{1\columnwidth}{1pt}}%
    -}
    +\newenvironment{DUCLASSrulebelow}{}{\noindent
    +                                  \rule[0.5ex]{1\columnwidth}{1pt}}
    

    +1 clear begin/end of wrapper in the .tex source

    -}% end class wrapper
    +\end{DUenv}
    

    -1 more and more complicated boilerplate code

    +% class handling environment (wrapper for block-level elements)
    +% \begin{DUENV}{spam} tries \DUENVspam and \end{DUENVspam} tries    \endDUENVspam
    +\newenvironment{DUenv}[1]%
    +  {\def\DUxenvxname{DUCLASS#1}% arg cannot be used in end-part of environment.
    +   \csname \DUxenvxname\endcsname}%
    +  {\csname end\DUxenvxname \endcsname}%
    

    -1 more nesting (one nesting level per class argument

    -{ \DUclass{compact} \DUclass{enumerateitems}%
    +\begin{DUenv}{compact}%
    +\begin{DUenv}{enumerateitems}%
    \begin{itemize}
     ...
    -}% end class wrapper
    +\end{DUenv}
    +\end{DUenv}
    
     
  • Günter Milde

    Günter Milde - 2017-05-04
    • status: open --> closed-fixed
    • Group: --> None
     
  • Günter Milde

    Günter Milde - 2017-05-04

    The "class wrapper" for environments (block-level elements) is not in the SVN repo.

     
  • Kirill Smelkov

    Kirill Smelkov - 2017-05-05

    Günter thanks for getting this topic eventualy merged even if via different approach.

     

Log in to post a comment.