我为我的大学文档制作了一个 LaTeX 模板,但我无法制作,因为\section
我收到标题错误。这是我的文档模板(必须将其保存为aqademia.sty
):
\ProvidesPackage{aqademia}
\RequirePackage{titling}
% Package options
\RequirePackage{etoolbox}
\RequirePackage{kvoptions}
\DeclareStringOption[CC] {ltype}
\DeclareStringOption[by-nc-sa] {lmodifier}
\DeclareStringOption[4.0] {lversion}
\DeclareStringOption[\thetitle]{title}
\DeclareStringOption[3]{tab}
\ProcessKeyvalOptions{aqademia}
\RequirePackage{xifthen}
% Licence options
\RequirePackage[type={\aqademia@ltype}, % Createve commons
modifier = {\aqademia@lmodifier}, % Attribution - NonCommercial - ShareAlike
version = {\aqademia@lversion} % 4.0 International
]{doclicense}
% Fonts
\RequirePackage{amsfonts}
\RequirePackage{amsmath}
\RequirePackage{fontspec}
\setmonofont[Ligatures=TeX]{Liberation Mono}
% Physical properties and text shaping and placement
\RequirePackage{vmargin}
\setpapersize{A4}
\setmarginsrb{2 cm} % Left margin
{1.5 cm} % Top margin
{2 cm} % Text width
{1.5 cm} % Text height
{1 cm} % Header height
{0.5 cm} % Header separation
{0 cm} % Footer height
{1 cm} % Footer separation
\RequirePackage[bottom, % Push all footnotes to the bottom of the page
multiple, % Allow formatting multiple footnotes for a single term
norule % Remove the rule above the footnotes
]{footmisc}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\aqademia@title}
\rhead{\theauthor}
\cfoot{\thepage}
\RequirePackage{titlesec}
\titleformat{\chapter}[block]{\normalfont\bfseries\Huge}{Chapter~\thechapter:\\}{0pt}{}[]
\titleformat{\section}[block]{\normalfont\bfseries\huge}{\S\thesection:~}{0pt}{}[]
\titleformat{\subsection}[block]{\normalfont\bfseries\Large}{\S\thesubsection:~}{0pt}{}[]
\titleformat{\subsubsection}[block]{\normalfont\bfseries\large}{\S\thesubsubsection:~}{0pt}{}[]
\titlespacing*{\chapter}{0pt}{0pt}{30pt}
\RequirePackage{hyperref}
\hypersetup{colorlinks = true,
linkcolor = black,
filecolor = black,
urlcolor = darkgray
}
\RequirePackage[toc,page]{appendix}
\RequirePackage{csquotes}
\RequirePackage{parskip}
\RequirePackage{url}
% Colour and graphics settings
\RequirePackage{xcolor}
\definecolor{listing-background} {HTML} {f7f7f7}
\definecolor{listing-numbers} {HTML} {8e8e8e}
\definecolor{listing-text-color} {HTML} {2c2c2c}
\definecolor{listing-keyword} {HTML} {6a2398}
\definecolor{listing-keyword-2} {HTML} {1284CA} % additional keywords
\definecolor{listing-keyword-3} {HTML} {9137CB} % additional keywords
\definecolor{listing-identifier} {HTML} {2467be}
\definecolor{listing-string} {HTML} {568a34}
\definecolor{listing-comment} {HTML} {8e8e8e}
% Tables
\RequirePackage{array}
% https://tex.stackexchange.com/questions/12703/how-to-create-fixed-width-table-columns-with-text-raggedright-centered-raggedlef
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\RequirePackage{booktabs}
% Listings
\RequirePackage{listings}
\lstdefinestyle{aqademia-listings}{basicstyle = \color{listing-text-color}\linespread{1.0}\small\ttfamily{},
backgroundcolor = \color{listing-background},
numbers = left,
breaklines = true,
breakindent = 0pt,
frame = single,
xleftmargin = 0cm,
framexleftmargin = 0.08cm,
tabsize = \aqademia@tab,
numberstyle = \color{listing-numbers},
keywordstyle = {\color{listing-keyword}\bfseries},
keywordstyle = {[2]\color{listing-keyword-2}\bfseries},
keywordstyle = {[3]\color{listing-keyword-3}\bfseries\itshape},
sensitive = true,
identifierstyle = \color{listing-identifier},
commentstyle = \color{listing-comment},
stringstyle = \color{listing-string},
showstringspaces = false,
escapeinside = {/*@}{@*/}, % Allow LaTeX inside these special comments
literate =
{á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'\i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
{Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1
{à}{{\`a}}1 {è}{{\'e}}1 {ì}{{\`\i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1
{À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1
{ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"\i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
{Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
{â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^\i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
{Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1
{œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1
{ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
{€}{{\EUR}}1 {£}{{\pounds}}1 {«}{{\guillemotleft}}1
{»}{{\guillemotright}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1
{…}{{\ldots}}1 {≥}{{>=}}1 {≤}{{<=}}1 {„}{{\glqq}}1 {“}{{\grqq}}1
{”}{{''}}1
}
\lstset{escapechar=@,style=aqademia-listings}
% Standalone command definitions and redefinitions
% \aqappendices -> Start appendix format for the rest of the document
% \aqtitle -> Render the title page
% \code -> Print text in monospaced font its size scaled down to the regular font size
\newcommand{\aqchap}[1]{%
\titleformat{\chapter}[block]
{\normalfont\bfseries\Huge}{#1\thechapter:\\}{0pt}{}[]
}
\newcommand{\aqsec}[1]{%
\titleformat{\section}[block]
{\normalfont\bfseries\huge}{#1\thesection:~}{0pt}{}[]
}
\newcommand{\aqssec}[1]{%
\titleformat{\subsection}[block]
{\normalfont\bfseries\Large}{#1\thesubsection:~}{0pt}{}[]
}
\newcommand{\aqsssec}[1]{%
\titleformat{\subsubsection}[block]
{\normalfont\bfseries\large}{#1\thesubsubsection:~}{0pt}{}[]
}
\newcommand{\aqapp}[1]{%
\setcounter{chapter}{0}
\renewcommand{\thesection}
{\MakeUppercase{\alph{chapter}}.\arabic{section}}
\renewcommand{\thesubsection}
{\MakeUppercase{\alph{chapter}}.\arabic{section}.\arabic{subsection}}
\renewcommand{\thesubsubsection}
{\MakeUppercase{\alph{chapter}}.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}
\aqchap{#1}
}
\newcommand{\aqtitlepage}[4][]{%
\begin{titlepage}
\begin{center}
\includegraphics[scale = 0.75]{titlepage.png}\\[0.5cm]
\ifthenelse{\isempty{#2}}{}
{\textsc{\Huge{#2}}\\}
\ifthenelse{\isempty{#3}}
{\rule{\linewidth}{0.2 mm}\\[0.3 cm]}
{\rule{\linewidth}{0.2 mm}\\}
{\huge\bfseries\thetitle\ifthenelse{\isempty{#3}}{}{~---~#3\\}}
\rule{\linewidth}{0.2 mm}\\[1 cm]
\vfill
\Large{\textbf{\theauthor}}
\ifthenelse{\isempty{#4}}{}
{\\[0.1cm]\large{\url{#4}}}\\[0.5 cm]
\large{\thedate}\\[1.5 cm]
\end{center}
\ifthenelse{\equal{#1}{nolicense}}
{}
{\doclicenseThis}
\end{titlepage}
}
\newcommand{\code}[1]{%
\begingroup\fontsize{9pt}{12pt}\selectfont\texttt{#1}\endgroup
}
以下是文档序言:
\documentclass[10pt]{report}
% Language and input encoding
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
% Document settings
\usepackage{titling}
\author{Atanasio José Rubio Gil}
\title{Algorítmica}
\date{\today}
\usepackage[title=\thetitle]{aqademia}
\aqchap{Tema~}
\aqssec{}
\usepackage{tikz}
\usepackage{pgfplots}
% Document composition
\begin{document}
\aqtitlepage{Grado en Ingeniería Informática}
{Teoría}
{https://github.com/Groctel/ugr-informatica}
\tableofcontents
\chapter{La eficiencia de los algoritmos}
\section{El concepto de algoritmo}
Un algoritmo\footnote{La palabra \textit{algoritmo} proviene del nombre del matemático persa del siglo IX Abd Allah Muhhamad ibn Musa \textbf{al-Khwarizmi}.} es una \textit{secuencia finita ordenada de pasos exentos de ambigüedad tal que, al llevarse a cabo con fidelidad, dará como resultado la tarea para la que se ha diseñado}.
De esta definición podemos extraer algunos términos clave: % ...
\end{document}
xelatex
尝试解析时引发错误\section
并得到以下输出:
Package pgfplots Warning: running in backwards compatibility mode (unsuitable t
ick labels; missing features). Consider writing \pgfplotsset{compat=1.16} into
your preamble.
on input line 25.
(/usr/share/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texmf-dist/tex/latex/amsfonts/umsb.fd)
Underfull \hbox (badness 7451) in paragraph at lines 29--29
[]\TU/lmr/m/n/10 Esta obra está bajo una licencia [][]Creative Commons « Recon
ocimiento-
(/usr/share/texmf-dist/tex/generic/oberdiek/se-ascii-print.def) [1]
(./ALG - Teoría.toc) [1]
Capítulo 1.
! Argument of \language@active@arg~ has an extra }.
<inserted text>
\par
l.35 \section{El concepto de algoritmo}
?
Runaway argument?
! Paragraph ended before \language@active@arg~ was complete.
<to be read again>
\par
l.35 \section{El concepto de algoritmo}
?
[2] (./ALG - Teoría.aux) )
Output written on ALG - Teoría.pdf (3 pages).
Transcript written on ALG - Teoría.log.
我在模板或序言中做错了什么?我在模板存储库中构建演示文件时没有遇到任何问题。这可能是一个babel
错误吗?
答案1
显示相同错误的更合理的测试文件是
\documentclass[10pt]{report}
% Language and input encoding
\usepackage[spanish]{babel}
% Document settings
% section related lines from local package
\RequirePackage{titlesec}
\titleformat{\section}[block]{\normalfont\bfseries\huge}{\S\thesection:~}{0pt}{}[]
% Document composition
\begin{document}
\section{El concepto de algoritmo}
z
\end{document}
~
标题中的 显然与 babel spanish 的使用相冲突,用~
正常的空格替换它会导致错误
\titleformat{\section}[block]{\normalfont\bfseries\huge}{\S\thesection: }{0pt}{}[]