汇编文章集的章节样式

汇编文章集的章节样式

在此处输入图片描述

假设每个章节都是一篇文章(手动复制或排版文章)。当然,文章标题将用作章节标题。如何定义副标题、作者、日期和来源的部分,并提供选项来自定义每个部分。

以及如何将它们自动生成为目录中的作者文章标题或文章标题(作者)?

我使用 pdflatex 工作,我更喜欢不会强迫我使用像这样的批发包的解决方案memoir

答案1

请参阅final最后的版本。

这是一个key-value基于的方法,对命令进行了轻微的重新定义\chapter和修改\@makechapterhead

ToC由于我现在没有太多时间,所以事情还没有完成,但我会在几个小时后尝试回来做这件事。

\documentclass{book}

\usepackage{xkeyval}
\usepackage{xparse}

\makeatletter
\let\latex@chapter\chapter


\define@key{blackened}{journal}[]{%
  \def\KVBlackenedJournal{#1}%
}


\define@key{blackened}{subtitle}[]{%
  \def\KVBlackenedSubtitle{#1}%
}

\define@key{blackened}{author}[]{%
  \def\KVBlackenedAuthor{#1}%
}

\define@key{blackened}{date}[\today]{%
  \def\KVBlackenedDate{#1}%
}


\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
%    \ifnum \c@secnumdepth >\m@ne
%      \if@mainmatter
%        \huge\bfseries \@chapapp\space \thechapter
%        \par\nobreak
%        \vskip 20\p@
%      \fi
%    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 20\p@
  }
  {%
    \centering 

    {\Large\textbf{\KVBlackenedSubtitle}}%
    \vskip 20\p@
    {\large \textit{by \KVBlackenedAuthor}}%
    \vskip 20\p@
    {\textsc{\KVBlackenedDate}}%
    \vskip 10\p@
    {\textsc{\KVBlackenedJournal}}%

  }%
}



\RenewDocumentCommand{\chapter}{somO{}}{%
  \setkeys{blackened}{author={},date={\today},journal={Journal of Dinosaurs},subtitle={It's my theory},#4}%
  \IfBooleanTF{#1}{%
    \latex@chapter*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@chapter[#2]{\centering #3}%
    }{%
      \latex@chapter[#3]{\protect\centering #3}%
    }%
  }%
}
\makeatother


\begin{document}
\tableofcontents
\chapter{Theory of Brontosaurs}[author={Ann Elk}]
\chapter{Theory of negative numbers}[author={Peter Tingley},journal={Journal of Everything}]

\end{document}

更新

\documentclass{book}

\usepackage{xkeyval}
\usepackage{xparse}


\newlength{\blackenedafterdateskip}
\newlength{\blackenedaftertitleskip}
\newlength{\blackenedaftersubtitleskip}
\newlength{\blackenedafterauthorskip}
\newlength{\blackenedafterjournalskip}

\makeatletter
\let\latex@chapter\chapter


\setlength{\blackenedafterdateskip}{10\p@}
\setlength{\blackenedafterauthorskip}{20\p@}
\setlength{\blackenedaftertitleskip}{20\p@}
\setlength{\blackenedaftersubtitleskip}{10\p@}
\setlength{\blackenedafterjournalskip}{0\p@}


\define@key{blackened}{journal}[]{%
  \def\KVBlackenedJournal{#1}%
}


\define@key{blackened}{subtitle}[]{%
  \def\KVBlackenedSubtitle{#1}%
}

\define@key{blackened}{author}[]{%
  \def\KVBlackenedAuthor{#1}%
}

\define@key{blackened}{date}[\today]{%
  \def\KVBlackenedDate{#1}%
}


\newcommand{\BlackenedDisplayDateStyle}[1]{%
  \textsc{#1}%
}

\newcommand{\BlackenedDisplayAuthorStyle}[1]{%
  {\large\textit{by #1}}%
}

\newcommand{\BlackenedDisplaySubtitleStyle}[1]{%
  {\Large\textbf{#1}}%
}

\newcommand{\BlackenedDisplayJournalStyle}[1]{%
  {\textsc{#1}}%
}

\newcommand{\DisplayDate}[1]{%
  \ifx#1\@empty%
  \else%
  \BlackenedDisplayDateStyle{#1}%
  \vskip\blackenedafterdateskip%
  \fi%
}

\newcommand{\DisplayAuthor}[1]{%
  \ifx#1\@empty%
  \else%
  \BlackenedDisplayAuthorStyle{#1}%
  \vskip\blackenedafterauthorskip%
  \fi%
}

\newcommand{\DisplaySubtitle}[1]{%
  \ifx#1\@empty%
  \else%
  \BlackenedDisplaySubtitleStyle{#1}%
  \vskip\blackenedaftersubtitleskip%
  \fi%
}

\newcommand{\DisplayJournal}[1]{%
  \ifx#1\@empty%
  \else%
  \BlackenedDisplayJournalStyle{#1}%
  \vskip\blackenedafterjournalskip%
  \fi%
}



\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
%    \ifnum \c@secnumdepth >\m@ne
%      \if@mainmatter
%        \huge\bfseries \@chapapp\space \thechapter
%        \par\nobreak
%        \vskip 20\p@
%      \fi
%    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 20\p@
  }
  {%
    \centering 

    \DisplaySubtitle{\KVBlackenedSubtitle}%
    \DisplayAuthor{\KVBlackenedAuthor}%
    \DisplayDate{\KVBlackenedDate}%
    \DisplayJournal{\KVBlackenedJournal}%

  }%
}




\RenewDocumentCommand{\chapter}{somO{}}{%
  \setkeys{blackened}{author={},date={\today},journal={Journal of Dinosaurs},subtitle={It's my theory},#4}%
  \IfBooleanTF{#1}{%
    \latex@chapter*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@chapter[#2]{\centering #3}
    }{%
      \latex@chapter[#3]{\protect\centering #3}
    }%
  }%
}
\makeatother

\begin{document}
\tableofcontents
\chapter{Theory of Brontosaurs}[author={Ann Elk},date={}]
\chapter{Theory of negative numbers}[author={Peter Tingley},journal={Journal of Everything}]
\chapter{Invisible}[author={},journal={},date={},subtitle={}]

\end{document}

前面还有重担 ;-)

\documentclass{book}

\usepackage{xkeyval}
\usepackage{xparse}
\usepackage{totcount}
\usepackage{morewrites}

\newcounter{dummycounter}
\newcounter{authorposition}
\newtotcounter{authorcounter}

\makeatletter
\let\latex@chapter\chapter

\def\latex@starttoc#1{%
  \begingroup
  \makeatletter
  \@input{\jobname.#1}%
  \if@filesw
  \expandafter\newwrite\csname tf@#1\endcsname
  \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
  \fi
  \@nobreakfalse
  \endgroup
}

\DeclareRobustCommand\authortoctext[1]{%
  {%
    \addvspace{10pt}\nopagebreak\leftskip0em\relax
    \rightskip \@tocrmarg\relax
    \noindent\itshape#1\par\addvspace{-7pt}}
}


\newcommand{\NoNameAuthor}{Unknown}
\newcommand{\authortocname}{List of Authors}

\newcommand{\BlackenedSectionDefaultOrder}{subtitle,author,date,journal,url} % Default sections 

\NewDocumentCommand{\DeclareArticleSection}{mm+m}{%
  \define@key{blackened}{#1}{%
    \expandafter\def\csname kvblackened#1\endcsname{##1}
  }%
  \expandafter\newlength\csname blackenedafter#1skip\endcsname%
  \expandafter\setlength\csname blackenedafter#1skip\endcsname{#2}%
  \expandafter\newcommand\csname blackened#1displaystyle\endcsname[1]{#3}%

  \expandafter\newcommand\csname display#1\endcsname{%
    \expandafter\ifx\csname kvblackened#1\endcsname\@empty%
    \else%
    \csname blackened#1displaystyle\endcsname{\csname kvblackened#1\endcsname}
    \vskip\csname blackenedafter#1skip\endcsname%
    \fi%
  }%
}



\define@key{blackened}{order}[]{%
  \def\KVBlackenedOrder{#1}%
}

\DeclareArticleSection{journal}{10\p@}{\textsc{#1}}
\DeclareArticleSection{subtitle}{20\p@}{{\Large\textbf{#1}}}
\DeclareArticleSection{author}{20\p@}{{\large\textit{by #1}}}
\DeclareArticleSection{date}{20\p@}{\textsc{#1}}
\DeclareArticleSection{url}{10\p@}{\texttt{#1}}


\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
%    \ifnum \c@secnumdepth >\m@ne
%      \if@mainmatter
%        \huge\bfseries \@chapapp\space \thechapter
%        \par\nobreak
%        \vskip 20\p@
%      \fi
%    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 20\p@
  }
  {%
    \centering 

    \DisplayArticleSections{\KVBlackenedOrder}

  }%
}



\ExplSyntaxOn
\seq_new:N \l__blackened_authornames_seq

% This is the command that loops the order of sections
\NewDocumentCommand{\DisplayArticleSections}{m}{%
  \tl_set:Nx \l_tmpb_tl {#1} % Expand it
  \seq_set_split:NnV \l_tmpb_seq {,} {\l_tmpb_tl} 
  \seq_map_inline:Nn \l_tmpb_seq {
    \cs_if_exist:cT {display##1}{%  
      \use:c {display##1}  % Call the \display##1 stuff
    }
  } 
}


\NewDocumentCommand{\AddAuthorName}{m}{%
  \tl_set:Nx \l_tmpa_tl {#1}
  \tl_if_empty:NTF \l_tmpa_tl {%
    \tl_set:Nn \l_tmpb_tl {\NoNameAuthor}
  }{%
    \tl_set:Nx \l_tmpb_tl {#1}
  }
  \tl_set_eq:NN  \l_tmpa_tl  \l_tmpb_tl % Copy the 'real name'
  \seq_if_in:NVTF \l__blackened_authornames_seq {\l_tmpa_tl} {
    \setcounter{dummycounter}{0}
    \seq_map_inline:Nn \l__blackened_authornames_seq {%
      \stepcounter{dummycounter}%
      \str_if_eq_x:nnT {##1} {\l_tmpa_tl} {% 
        \setcounter{authorposition}{\number\value{dummycounter}}
        \seq_map_break: % Break out, we've found the number
      }
    }% End of mapping
  }{%
    \seq_put_right:NV \l__blackened_authornames_seq {\l_tmpa_tl}
    \stepcounter{authorcounter}%
    \setcounter{authorposition}{\number\value{authorcounter}}% 
    \addtocontents{\arabic{authorposition}toc}{\authortoctext{\l_tmpa_tl}}%
  }
  \seq_remove_duplicates:N \l__blackened_authornames_seq
}


\ExplSyntaxOff

\newcommand{\authortableofcontents}{%
  \chapter*{\authortocname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
  \setcounter{dummycounter}{0}%
  % Now get all the author specific toc files
  \loop 
  \ifnum\value{dummycounter} < \numexpr\totvalue{authorcounter}+1
  \stepcounter{dummycounter}%
  \latex@starttoc{\@arabic\c@dummycounter toc}%
  \repeat%
}



\RenewDocumentCommand{\chapter}{somO{}}{%
  \setkeys{blackened}{order=\BlackenedSectionDefaultOrder,author={},url={tex.stackexchange.com},date={\today},
    journal={Journal of Dinosaurs},subtitle={It's my theory},#4}%
  \IfBooleanTF{#1}{%
    \latex@chapter*{#3}%
  }{%
    \AddAuthorName{\kvblackenedauthor}%
    \IfValueTF{#2}{%
      \latex@chapter[#2]{\centering #3}
    }{%
      \latex@chapter[#3]{\protect\centering #3}
    }%
    \addcontentsline{\arabic{authorposition}toc}{chapter}{%
      \protect\numberline{\thechapter}#3}%
  }%
}
\makeatother




\begin{document}
\authortableofcontents
\tableofcontents
\chapter{Theory of Brontosaurs}[author={Ann Elk},order={subtitle,author,journal,url,date}]
\chapter{Theory of negative numbers}[author={Peter Tingley},journal={Journal of Everything}]
\chapter{Invisible}[author={},journal={},date={},subtitle={}]
\chapter{Extended Theory of Brontosaurs}[author={Ann Elk},order={journal,date,author,url,subtitle}]

\end{document}

在此处输入图片描述

相关内容