2

enter image description here

Say each chapter is an article (manually copying or typesetting the article). Naturally, article title will be used as chapter title. How do I define sections for subtitle, author, date, and source with options to possibly customize each one.

And how do I auto-generate them as Article Title by Author, or Article Title (Author) in TOC?

I work in pdflatex and I prefer solutions that would not force me to use wholesale packages like memoir.

6
  • How do you bring your article in your 'book'? Manually copying the article code? And you don't want to use memoir? I remember to have answered a question about the Author Toc some months ago – user31729 Nov 24 '15 at 10:02
  • @Christian Manually copying or typesetting the articles. It is not that I am against memoir package or such, just that I am not familiar with them. – blackened Nov 24 '15 at 10:10
  • Well, I am neither a fan of memoir nor opposing it really -- it has some nice features and some which isn't not so well designed. I think, it's best to use book then – user31729 Nov 24 '15 at 10:13
  • Do your articles have sections etc. as well? – user31729 Nov 24 '15 at 10:19
  • @Christian Yes. I am not after solving a one time job, and would rather have a template to be used in many similar cases. An article may have sections, and, perhaps, subsections. – blackened Nov 24 '15 at 10:23
4

See the final version at the end.

Here's a key-value-based approached with a slight redefinition of \chapter and a modification of the \@makechapterhead command.

The ToC - stuff is not yet done since I do not have much time right now, but I'll try to return to it in a few hours.

\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}

Update

\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}

Heavy stuff ahead ;-)

\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}

enter image description here

9
  • Is it possible that the defined sections do not take up space if left empty? – blackened Nov 24 '15 at 11:29
  • @blackened: Yes, I will change later on – user31729 Nov 24 '15 at 11:34
  • 1
    @blackened: Sorry for the delay -- empty items are now omitted and the spacing is skipped too. You can change the style more easily now as well. I am still working on the Author - ToC – user31729 Nov 25 '15 at 4:11
  • Thank you for sparing your time. 1) Looking at some articles, I noticed that I will potentially need a section for website url. Would you kindly add a section for that. 2) Will I able to customize the order of the fields. Say, I want it in the order of Author, Chapter Title, Subtitle, Date, etc.? – blackened Nov 25 '15 at 9:24
  • 1
    @blackened: See the update please -- you can now choose the order in which the sections appear and readily add own sections with \DeclareArticleSection command. The Author-ToC is there too -- you have to decide how it looks -- I think, I should make a class/package out of this 'laboursome' stuff ;-) – user31729 Nov 25 '15 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.