在书籍类模板中为标题、章节、作者制作自定义命令

在书籍类模板中为标题、章节、作者制作自定义命令

我正在尝试制作一本科学杂志(免费电子书),其中包含来自不同作者的科学和数学文章集。我得出了以下 MWE:

当前的test_style.sty

% !TEX root = main.tex
% \RequirePackage[banglamainfont=Kalpurush,      % For writing Bangla. but not necessary for the MWE
%                 banglattfont=Kalpurush,
%                ]{latexbangla}

% table of contents formatting      
\RequirePackage{tocloft}                  
\def\cftchapteraftersnum{.}                      % Tried to put a full stop after chapter numbers in ToC. But not working! 
% \renewcommand\cftchapafterpnum{\vskip-5pt}     % Decreasing the line spacing between the names of chapters

\RequirePackage{placeins}

\RequirePackage{docmute}
\RequirePackage{amsmath, amsfonts, amssymb, amsthm}
%\RequirePackage{physics}
\RequirePackage{graphicx}
\RequirePackage{mathtools}
\RequirePackage{extarrows}
\RequirePackage{enumitem}
\RequirePackage{lipsum}
\RequirePackage{mwe}
\RequirePackage[papersize={5.5in, 8.5in}, margin=0.8in, headheight=14.72pt]{geometry}
\linespread{1.15}

\RequirePackage{csquotes}             % https://tex.stackexchange.com/q/39285/114006
\RequirePackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
}
\urlstyle{same}

% Adding header ann footer on pages
\RequirePackage{fancyhdr}
\fancypagestyle{plain}{
  \fancyhf{}                              % clear all header and footer fields
  \lhead{\spaceskip=5pt\href{<url>}{Magazine Name}}
  \cfoot{\thepage}
  \renewcommand{\headrulewidth}{0.5pt}
  \renewcommand{\footrulewidth}{0.5pt}
}

\RequirePackage{pdfpages}

\allowdisplaybreaks

\graphicspath{ {./img/} }

\RequirePackage{titling}

\RequirePackage{titlesec}
\titleformat{\chapter}[display]
{\raggedright\normalfont\huge\bfseries}{{\Huge\S\,}\ \thechapter}{20pt}{\Huge}

\titlespacing*{\chapter} {0pt}{0pt}{40pt}     % this alters "before" spacing (the second length argument) to 0


% Adding Chapter Authors after chapter title:   https://tex.stackexchange.com/a/156865/114006
\RequirePackage{suffix}

\newcommand\chapterauthor[1]{\authortoc{#1}\printchapterauthor{#1}}
\WithSuffix\newcommand\chapterauthor*[1]{\printchapterauthor{#1}}

\makeatletter
\newcommand{\printchapterauthor}[1]{%
  {\parindent0pt\vspace*{-25pt}%
  \linespread{1.1}\spaceskip=7pt\Large\scshape#1%
  \par\nobreak\vspace*{35pt}}
  \@afterheading%
}
\newcommand{\authortoc}[1]{%
  \addtocontents{toc}{\vskip-10pt}%
  \addtocontents{toc}{%
    \protect\contentsline{chapter}%
    {\hskip1.5em\mdseries\scshape\protect\footnotesize#1}{}{}}
  \addtocontents{toc}{\vskip-5pt}%
}
\makeatother

% Command for chapter title photo                    % https://tex.stackexchange.com/a/91620/114006
 \newcommand{\chapterphoto}[1]{\includegraphics[width=\textwidth]{#1}\vspace{0.5cm}}

当前的test_title.tex

\title{
\includegraphics[width=0.5\textwidth]{example-image}~\\[1cm]
A Collection of Articles}
\author{Edited by\\
Editor 1 Name\\
Editor 2 Name\\}
\date{}

\begin{titlepage}
\includepdf[pages=1, fitpaper]{cover}
\thispagestyle{empty}
\predate{\centering}
\postdate{\vfill\hfill \footnotesize{\\Designed by \\ Designer \\  © \href{<url>}{Book Template Source}\\}\hfill}     % https://tex.stackexchange.com/a/199356/114006
\maketitle
\end{titlepage}

\pagenumbering{roman}
\newpage
\setcounter{tocdepth}{0}
\tableofcontents
\newpage
\pagestyle{plain}
\pagenumbering{arabic}

当前的main.tex

% !TEX program = xelatex
\documentclass[12pt, oneside]{book}
\usepackage{test_style}

\begin{document}

\frontmatter

\include{test_title}

\mainmatter

%article 1   ------------- edit its names as necessary 
\chapter[Chapter One Title on ToC]{                                                                             % Short chapter title to show on the table of contents
\chapterphoto{example-image-golden}                       
\href{<chapter url>}{Chapter One Title: Introduction}}                                                               % Full chapter title to show on the chapter title page 
\chapterauthor{\href{<author url>}{Author}}   % Chapter author name with url 
\newpage
\section{Introduction}
\lipsum                                             

\end{document}

现在我想配置test_style.stytest_title.tex,以便我可以通过设置自定义命令来生成相同的输出,并附带一些附加功能。配置应采用以下方式main.tex

我的愿望main.tex

% !TEX program = xelatex
\documentclass[12pt, oneside]{book}
\usepackage{test_style}

\begin{document}

\bookcover{cover}              
\booklogo{example-image}       
\booktitle{A collection of Articles}            
\bookeditor{Editor 1 Name\\ Editor 2 Name}
\bookdesigner{Designer Name}
% These are currenly done in my `test_title.tex' file. but I want to get them by the above commands. 
\pageheader{Book Name}
\bookurl{<book url>}                        % Hyperlink on the page header
 
\chapter[Chapter One Title on ToC]{Chapter One Title: Introduction} 
\chapterphoto{example-image-golden}         % The photo size should be optimized such that the chapter number, photo, name and author name always remain in the same page                                                      
\chapterurl{<chapter url>}                  % Hyperlink on the chapter title, link to the web version of the chapter, but this url should not be on ToC  
\chapterauthor{Chapter Author Name}         % Chapter author name
\chapterauthorurl{<author url>}             % Hyperlink on the author name, link to the author website, but the url should not be on ToC

\newpage
\section{Introduction}
\lipsum                                             

\end{document}

我认为我的问题可以分为两个主要部分:

  • 制作与书籍相关的自定义命令\book...
  • 制作与章节相关的自定义命令\chapter...

基本上,我希望配置样式文件并设置那些自定义命令,以便用户只需在文件中工作和编辑main.tex,而不一定在test_style.sty或中test_title.tex。如何获得这些功能?(请不要错过阅读中的评论main.tex)。

期待得到您的答案!我知道这已经成为一个大问题。但我觉得制作这些自定义命令会相互关联。所以,我把这些问题放在一起。但请随意单独回答我的问题的任何特定部分。

相关内容