Hyperref 错误不完整 \iffalse

Hyperref 错误不完整 \iffalse

我正在尝试将hyperref包与我的论文一起使用,我在这里放了一个简化版本:

\documentclass[a4paper,twoside,12pt,notitlepage,openright]{article}
\usepackage[ansinew]{inputenc}
\usepackage[dvips,dvipdfmx]{graphicx} %[dvips] to used with .eps figures
\usepackage{bmpsize} % insert pdf figures
\usepackage{natbib}
\usepackage{lastpage}   % page count
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[english]{babel}
\usepackage[intoc]{nomencl} % including table of content
\usepackage{ifthen}
\usepackage[hmargin=3.0cm,vmargin=3.6cm]{geometry} % setting marginals
\usepackage{fancyhdr,extramarks}  % header ja footer manipulation
\usepackage{times}  % to change font to times
\usepackage{setspace} % for linespacing
\usepackage{color,soul} % for highlighting text
\usepackage[version=4]{mhchem} % for chemical formulas
\usepackage{url} % fix compilation error for url used in the references
\usepackage{gensymb} % degree celcius
\usepackage{enumerate} %use roman labels in enumerate

\singlespacing

\pagestyle{fancy}
\fancyhf{}% clearing the header and footer
\fancyhead[LE,RO]{\bfseries\thepage}    % page number to header
\fancyhead[LO]{\nouppercase{\bfseries\rightmark}}     %
\fancyhead[RE]{\nouppercase{\bfseries\leftmark}}%

\renewcommand\sectionmark[1]
 {\markboth{\thesection\ #1}{}}         % section name to header
\renewcommand\subsectionmark[1]
 {\markright{\thesubsection\ #1}}       % subsection name to header
\renewcommand{\headrulewidth}{0.5pt}    % ruler thickness between head and body
\renewcommand{\footrulewidth}{0pt}      % no ruler between body and footer

\setlength{\nomitemsep}{-\parsep}   % removing default extra skip between entries at nomenclature

\numberwithin{equation}{section}    % equation numbers with section numbers
\numberwithin{table}{section}       % table numbers with section numbers
\numberwithin{figure}{section}      % figure numbers with section numbers

% makeindex command needs to run at command prompt to create nomenclature list file
\makenomenclature % makeindex main_v2.nlo -s nomencl.ist -o main_v2.nls
%\bibpunct{(}{)}{;}{a}{,}{,}%

\usepackage{hyperref}

\begin{document}

\pagestyle{empty}
\include{abstract}
\addtocontents{toc}{\contentsline{section}{Abstract}{}{}}%

\end{document}

其中 abstract.tex 如下:

\section*{Abstract}

\textbf{My name}\\
\textbf{Title}\\
Year 2019\\
\pageref{LastPage} pages\\
XXXXXX\\
Cool dissertation\\
ISBN XXXX, ISBN XXXX (PDF), ISSN XXXXXX\\

something\\

more\\

about it.\\

Keywords: this, that, this that and that\\
UDC: XXXX : XXXX : XXXX\\

起初,添加会返回错误,因为必须将\usepackage{hyperref}中的参数数量从 3 更改为 4(或者按照我在某处看到的建议更改为 5)。在添加另一个 之后,它现在返回以下错误:\contentsline{}

!Incomplete \iffalse; all text was ignored after line 53
<inserted text>
\fi
The file ended while I was skipping conditional text.
! Emergency stop

我看到这个问题已经被问过了\usepackage{hyperref} 导致不完整的 \iffalse 错误但没有给出答案。

答案1

您需要保护 \contentsline 命令,最好将其直接放在 section 命令之后,以便它指向正确的位置:

\phantomsection
\section*{Abstract}
\addtocontents{toc}{\protect\contentsline{section}{Abstract}{}{}{}}%

相关内容