(是否有/如何制作)类似“枚举”的包/宏,但用于整个文档分段

(是否有/如何制作)类似“枚举”的包/宏,但用于整个文档分段

我刚刚发现了这个enumerate包,这让我很兴奋,因为不久前我在想一些类似的东西(选项,其中代表a\alph{<counter>}、等等),但用于整个文档的分段。也就是说,要在转录我的历史课时复制老师的符号,使用类似的东西(可能还有一些额外的语法来指定我们希望每个计数器何时重置为 0),而不是总是写A\Alph{<counter>}i\roman{<counter>}\usepackage[I/1/I/A/1/a]{sectioning}

\renewcommand{\thepart}{Tema \Roman{part}}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection .\Alph{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection .\arabic{subsubsection}}
\renewcommand{\theparagraph}{\thesubsubsection .\alph{paragraph}}

我以前放弃了这个想法,因为当时我不知道如何为这样的东西编写一个宏(特别是a-to- \alph{<actual-counter>}-like 部分),但现在我不仅在问自己是否不存在这样的包,而且还在问是否没有可以帮助我尝试编写这样的包的包,就像enumerate包为环境所做的enumerate那样(我也想知道是否可以将相同的方法应用于enumerateenumerate环境)。

所以简而言之,我的问题是:是否有软件包可以做到这一点或类似的事情,或者是否有软件包可以帮助我实现这一点或类似的事情?

答案1

据我所知,没有这样的包,但也许,这段代码会导致一个包(假设我有时间改进代码并编写包)

更新后的版本

句法:

  • I等仅使用 OP 请求的计数器格式化程序
  • I+等将前一个\the...格式化程序添加到前面,例如\thesubsection将用作\thesection \Roman{subsection}
  • I+.将在 之前添加一个点\Roman{...}

目前还不是最佳方案,但可以


\documentclass{book}

\usepackage{xparse}

\ExplSyntaxOn

\seq_new:N \l_galex_default_seq
\newcommand{\filldefaultseq}{%
  \seq_set_split:Nnn \l_galex_default_seq {/} {I+/A/I/A/1/a/i}
}

\seq_set_from_clist:Nn \l_sectionname_seq {part,chapter,section,subsection,subsubsection,paragraph,subparagraph}

\tl_gset:Nn \g_prepart_name {\space}
\tl_gset:Nn \g_prechapter_name {\thepart}
\tl_gset:Nn \g_presection_name {\thechapter}
\tl_gset:Nn \g_presubsection_name {\thesection}
\tl_gset:Nn \g_presubsubsection_name {\thesubsection}
\tl_gset:Nn \g_preparagraph_name {\thesubsubsection}
\tl_gset:Nn \g_presubparagraph_name {\theparagraph}

\tl_gset:Nn \g_part_structurename {Tema}
\tl_gset:Nn \g_chapter_structurename {}
\tl_gset:Nn \g_section_structurename {}
\tl_gset:Nn \g_subsection_structurename {}
\tl_gset:Nn \g_subsubsection_structurename {}
\tl_gset:Nn \g_paragraph_structurename {}
\tl_gset:Nn \g_subparagraph_structurename {}


\NewDocumentCommand{\ChangeCounterFormats}{o}{%
  \IfValueTF{#1}{%
    \seq_set_split:Nnn \l_tmpa_seq {/} {#1}
  }{
    \seq_set_eq:NN \l_tmpa_seq \l_galex_default_seq
  }
  \int_zero:N \l_tmpa_int
  \seq_map_inline:Nn \l_sectionname_seq {%
    \int_incr:N \l_tmpa_int
    \str_case_x:nn {\seq_item:Nn \l_tmpa_seq {\l_tmpa_int}}{%
      {I+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\Roman{##1}}}
      {i+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\roman{##1}}}
      {A+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\Alph{##1}}}
      {a+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\alph{##1}}}
      {1+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\arabic{##1}}}
      {I+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \Roman{##1}}}
      {i+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \roman{##1}}}
      {A+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \Alph{##1}}}
      {a+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \alph{##1}}}
      {1+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \arabic{##1}}}
      {I}{\expandafter\renewcommand\csname the##1\endcsname{\Roman{##1}}}
      {i}{\expandafter\renewcommand\csname the##1\endcsname{\roman{##1}}}
      {a}{\expandafter\renewcommand\csname the##1\endcsname{\alph{##1}}}
      {A}{\expandafter\renewcommand\csname the##1\endcsname{\Alph{##1}}}
      {1}{\expandafter\renewcommand\csname the##1\endcsname{\arabic{##1}}}
    }
  }
}
\ExplSyntaxOff

\setcounter{secnumdepth}{6}

\setcounter{tocdepth}{6}
\begin{document}
\tableofcontents

\filldefaultseq

\ChangeCounterFormats[I+/A/1+./i+./1+./i+./a+.]

\part{Foo}

\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\subsubsection{First subsubsection}
\paragraph{First paragraph}
\subparagraph{First subparagraph}



\part{Foo}

\chapter{Second chapter}
\section{Second section}
\subsection{Second subsection}
\subsubsection{Second subsubsection}
\paragraph{Second paragraph}
\subparagraph{Second subparagraph}


\chapter{Third chapter}
\section{Third section}
\subsection{Third subsection}
\subsubsection{Third subsubsection}
\paragraph{Third paragraph}
\subparagraph{Third subparagraph}

\end{document}

在此处输入图片描述

更新 2016/02/27

我创建了一个secfmt.sty用于更改计数器格式样式和驱动程序文件。

一些宏的名称已被更改,我添加了\StoreOriginalCounterFormats存储等\RestoreOriginalCounterFormats的宏\thepart并恢复它们(如果需要)

secfmt.sty

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{secfmt}

\RequirePackage{xparse}

\ExplSyntaxOn

% Data section 
\seq_new:N \g_secfmt_default_seq
\seq_gset_from_clist:Nn \g_secfmt_sectionname_seq {part,chapter,section,subsection,subsubsection,paragraph,subparagraph}


\@ifclassloaded{memoir}{%
  \seq_gput_left:Nn \g_secfmt_sectionname_seq {book}
  \seq_gput_left:Nn \g_secfmt_default_seq {A}
}{}


\tl_gset:Nn \g_prebook_name {} % Only relevant for `memoir.cls`

\@ifclassloaded{memoir}{%
  \tl_gset:Nn \g_prepart_name {\thebook}
}{
  \tl_gset:Nn \g_prepart_name {\space}
}

\tl_gset:Nn \g_prechapter_name {\thepart}
\tl_gset:Nn \g_presection_name {\thechapter}
\tl_gset:Nn \g_presubsection_name {\thesection}
\tl_gset:Nn \g_presubsubsection_name {\thesubsection}
\tl_gset:Nn \g_preparagraph_name {\thesubsubsection}
\tl_gset:Nn \g_presubparagraph_name {\theparagraph}

\tl_gset:Nn \g_book_structurename {Book}
\tl_gset:Nn \g_part_structurename {Tema}
\tl_gset:Nn \g_chapter_structurename {}
\tl_gset:Nn \g_section_structurename {}
\tl_gset:Nn \g_subsection_structurename {}
\tl_gset:Nn \g_subsubsection_structurename {}
\tl_gset:Nn \g_paragraph_structurename {}
\tl_gset:Nn \g_subparagraph_structurename {}

%% Function section

\NewDocumentCommand{\StoreOriginalCounterFormats}{}{%
  \seq_map_inline:Nn \g_secfmt_sectionname_seq {%
    \cs_gset_eq:cc {cs_orig_the##1} {the##1}
  }
}

\NewDocumentCommand{\RestoreOriginalCounterFormats}{}{%
  \seq_map_inline:Nn \g_secfmt_sectionname_seq {%
    \cs_gset_eq:cc {the##1} {cs_orig_the##1} 
  }
}

\AtBeginDocument{\StoreOriginalCounterFormats}

\NewDocumentCommand{\CreateDefaultCounterFormats}{o}{%
  \IfValueTF{#1}{%
    \seq_set_split:Nnn \g_secfmt_default_seq {/} {#1}
  }{%
    \seq_set_split:Nnn \g_secfmt_default_seq {/} {I+/A/I/A/1/a/i}
  }
}


\NewDocumentCommand{\ChangeCounterFormats}{o}{%
  \IfValueTF{#1}{%
    \seq_set_split:Nnn \l_tmpa_seq {/} {#1}
  }{
    \seq_set_eq:NN \l_tmpa_seq \g_secfmt_default_seq
  }
  \int_zero:N \l_tmpa_int % dummy counter
  \seq_map_inline:Nn \g_secfmt_sectionname_seq {%
    \int_incr:N \l_tmpa_int
    \str_case_x:nn {\seq_item:Nn \l_tmpa_seq {\l_tmpa_int}}{%
      {I+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\Roman{##1}}}
      {i+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\roman{##1}}}
      {A+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\Alph{##1}}}
      {a+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\alph{##1}}}
      {1+.}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name}.\arabic{##1}}}
      {I+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \Roman{##1}}}
      {i+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \roman{##1}}}
      {A+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \Alph{##1}}}
      {a+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \alph{##1}}}
      {1+}{\expandafter\renewcommand\csname the##1\endcsname{\tl_use:c {g_##1_structurename}\tl_use:c {g_pre##1_name} \arabic{##1}}}
      {I}{\expandafter\renewcommand\csname the##1\endcsname{\Roman{##1}}}
      {i}{\expandafter\renewcommand\csname the##1\endcsname{\roman{##1}}}
      {a}{\expandafter\renewcommand\csname the##1\endcsname{\alph{##1}}}
      {A}{\expandafter\renewcommand\csname the##1\endcsname{\Alph{##1}}}
      {1}{\expandafter\renewcommand\csname the##1\endcsname{\arabic{##1}}}
    }
  }
}
\ExplSyntaxOff


\endinput

driver.tex

\documentclass{book}

\usepackage{secfmt}

\CreateDefaultCounterFormats%

\setcounter{secnumdepth}{6}

\setcounter{tocdepth}{6}
\begin{document}
\tableofcontents


\ChangeCounterFormats[I+/A/1+./i+./1+./i+./a+.]

\part{First Part}

\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\subsubsection{First subsubsection}
\paragraph{First paragraph}
\subparagraph{First subparagraph}



\part{Second part}

\chapter{Second chapter}
\section{Second section}
\subsection{Second subsection}
\subsubsection{Second subsubsection}
\paragraph{Second paragraph}
\subparagraph{Second subparagraph}


\chapter{Third chapter}
\section{Third section}
\subsection{Third subsection}
\subsubsection{Third subsubsection}
\paragraph{Third paragraph}
\subparagraph{Third subparagraph}

\RestoreOriginalCounterFormats

\part{Third part}

\chapter{Third chapter}
\section{Third section}
\subsection{Third subsection}
\subsubsection{Third subsubsection}
\paragraph{Third paragraph}
\subparagraph{Third subparagraph}


\chapter{Fourth chapter}
\section{Fourth section}
\subsection{Fourth subsection}
\subsubsection{Fourth subsubsection}
\paragraph{Fourth paragraph}
\subparagraph{Fourth subparagraph}


\end{document}

相关内容