包含 + 嵌套部分

包含 + 嵌套部分

我正在使用 XSLT 生成一些 TeX 代码,这些代码将包含在主文档中。我事先不知道它将包含在哪个位置:它可能在 或 内sectionsubsection我如何在 html 中创建一个像一组嵌套 UL 一样的部分

<ul>
   <li>Hello</li>
   <li><ul>
      <li>World</li>
   </ul></li>
</ul>

我尝试过类似的事情:

\begin{section}
Hello
\begin{section}
World
\end{section}
\end{section>

但它不起作用:它们都具有相同的深度。

答案1

以下实现了一个mysection可以嵌套的环境,自动提升和降级部分类型以适应嵌套:

在此处输入图片描述

\documentclass{article}
\makeatletter
% Section
\@namedef{section@name@1}{section}
\expandafter\newlength\csname section@indent@1\endcsname\expandafter\setlength\csname section@indent@1\endcsname{\z@}
\expandafter\newlength\csname section@beforeskip@1\endcsname\expandafter\setlength\csname section@beforeskip@1\endcsname{-3.5ex \@plus -1ex \@minus -.2ex}
\expandafter\newlength\csname section@afterskip@1\endcsname\expandafter\setlength\csname section@afterskip@1\endcsname{2.3ex \@plus.2ex}
\@namedef{section@style@1}{\normalfont\Large\bfseries}
% Subsection
\@namedef{section@name@2}{subsection}
\expandafter\newlength\csname section@indent@2\endcsname\expandafter\setlength\csname section@indent@2\endcsname{\z@}
\expandafter\newlength\csname section@beforeskip@2\endcsname\expandafter\setlength\csname section@beforeskip@2\endcsname{-3.25ex\@plus -1ex \@minus -.2ex}
\expandafter\newlength\csname section@afterskip@2\endcsname\expandafter\setlength\csname section@afterskip@2\endcsname{1.5ex \@plus .2ex}
\@namedef{section@style@2}{\normalfont\large\bfseries}
% Subsubsection
\@namedef{section@name@3}{subsubsection}
\expandafter\newlength\csname section@indent@3\endcsname\expandafter\setlength\csname section@indent@3\endcsname{\z@}
\expandafter\newlength\csname section@beforeskip@3\endcsname\expandafter\setlength\csname section@beforeskip@3\endcsname{-3.25ex\@plus -1ex \@minus -.2ex}
\expandafter\newlength\csname section@afterskip@3\endcsname\expandafter\setlength\csname section@afterskip@3\endcsname{1.5ex \@plus .2ex}
\@namedef{section@style@3}{\normalfont\normalsize\bfseries}
% Paragraph
\@namedef{section@name@4}{subsubsection}
\expandafter\newlength\csname section@indent@4\endcsname\expandafter\setlength\csname section@indent@4\endcsname{\z@}
\expandafter\newlength\csname section@beforeskip@4\endcsname\expandafter\setlength\csname section@beforeskip@4\endcsname{3.25ex \@plus1ex \@minus.2ex}
\expandafter\newlength\csname section@afterskip@4\endcsname\expandafter\setlength\csname section@afterskip@4\endcsname{-1em}
\@namedef{section@style@4}{\normalfont\normalsize\bfseries}
% Subparagraph
\@namedef{section@name@5}{subsubsection}
\expandafter\newlength\csname section@indent@5\endcsname\expandafter\setlength\csname section@indent@5\endcsname{\parindent}
\expandafter\newlength\csname section@beforeskip@5\endcsname\expandafter\setlength\csname section@beforeskip@5\endcsname{3.25ex \@plus1ex \@minus .2ex}
\expandafter\newlength\csname section@afterskip@5\endcsname\expandafter\setlength\csname section@afterskip@5\endcsname{-1em}
\@namedef{section@style@5}{\normalfont\normalsize\bfseries}

\newcounter{section@level}
\newcommand{\unstepcounter}[1]{\addtocounter{#1}{-1}}
\newenvironment{mysection}
  {\stepcounter{section@level}%
   \@startsection{\@nameuse{section@name@\thesection@level}}
     {\thesection@level}
     {\@nameuse{section@indent@\thesection@level}}
     {\@nameuse{section@beforeskip@\thesection@level}}
     {\@nameuse{section@afterskip@\thesection@level}}
     {\@nameuse{section@style@\thesection@level}}}
  {\unstepcounter{section@level}}

\setcounter{secnumdepth}{5}
\makeatother
\begin{document}
\begin{mysection}{A section}
  Some text.
  \begin{mysection}{A subsection}
    Some text.
    \begin{mysection}{A subsubsection}
      Some text.
    \end{mysection}
    \begin{mysection}{A subsubsection}
      Some text.
      \begin{mysection}{A paragraph}
        Some text.
      \end{mysection}
      \begin{mysection}{A paragraph}
        Some text.
        \begin{mysection}{A subparagraph}
          Some text.
        \end{mysection}
      \end{mysection}
    \end{mysection}
  \end{mysection}
  \begin{mysection}{A subsection}
    Some text.
  \end{mysection}
\end{mysection}
\end{document}

章节定义取自article.cls

\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}
\newcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\bfseries}}
\newcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\bfseries}}
\newcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em}%
                                    {\normalfont\normalsize\bfseries}}
\newcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em}%
                                      {\normalfont\normalsize\bfseries}}

并按各部分的namelevelindentbeforeskip和细分afterskipstyle在哪里可以找到类似命令的帮助文件或文档\@startsectionLaTeX 的命令的帮助文件或文档?)。

每次调用mysection环境时,section@level都会降级到下一个最低的分段单元,并在环境结束时“取消降级”。没有进行深度结束测试,但这是可能的。

相关内容