`\url` 的奇怪问题

`\url` 的奇怪问题

我遇到了一个问题\url。当我使用它时,LaTeX(即带有 TeXstudio 的 pdflatex)不会结束编译。

我有一个包含多个.tex文件的主文档,每个文件都包含不同的章节。我正在使用natbibchapterbib。一切似乎都很好(例如,为了在每个章节中获取参考部分,我知道我必须bibtex在每个.aux文件上执行,等等)。我认为问题与此没有直接关系。

您会在下面找到我的主要文件。

当我停止该过程时(经过长时间的等待),我在 TeXstudio 收到此消息:

使用 @@BOOKMARK 扫描时文件已结束。\begin{document}

尽管我不确定这个错误信息是否重要。

您是否看到某些可能与此错误消息相关\url并导致此错误消息的内容?

% !TEX encoding = UTF-8 Unicode

\documentclass[a4paper,12pt]{book}

% PAQUETES AUXILIARES Y GENERALES
% ===============================

\usepackage[utf8]{inputenc}
\usepackage{xspace}
\usepackage{calc}
\usepackage{verbatim}

% FORMATO DE PÁGINA
% =================

\RequirePackage[a4paper,
top=1.63cm, bottom=2.64cm, outer=2.64cm,inner=2.64cm, 
headsep=0.63cm,footskip=1.00cm,headheight=0.37cm, 
bindingoffset=0cm
]{geometry}

\RequirePackage{setspace}
\setstretch{1.15}

\raggedbottom
\renewcommand{\topfraction}{1.0}
\renewcommand{\bottomfraction}{1.0}
\renewcommand{\textfraction}{0.0}
\renewcommand{\floatpagefraction}{1.0}
\usepackage{everysel}
\usepackage[bottom,multiple]{footmisc}
\usepackage{ragged2e}   
\usepackage{multicol}
\usepackage{afterpage}

% TIPOS DE LETRA Y EXPRESIONES MATEMÁTICAS
% ========================================

\usepackage[T1]{fontenc}
\usepackage[defaultfam,light,bold,proportional,lining]{montserrat}
\renewcommand*\oldstylenums[1]{{\fontfamily{Montserrat-TOsF}\selectfont #1}}
 % VER TAMBIÉN `mathastext` DESPÚES DE TODOS LOS PAQUETES MATEMÁTICOS
\usepackage[scaled=0.85]{beramono} % Tipo de letra para texto de ancho fijo (listados, etc.)
\usepackage{microtype}
\usepackage{textcase}
\usepackage{soul}
\usepackage{textfit}
\usepackage[centertags]{amsmath,mathtools} 
\allowdisplaybreaks[1]   
\usepackage{amssymb}
\usepackage{braket}
\usepackage{nicefrac}
\newcommand{\slfrac}[2]{\left.#1\middle/#2\right.}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\usepackage{bm} % Necessary for greek bold symbols. Usage: \bm{\mu}
\usepackage{relsize}
  % TO ENLARGE SUMATIONS SIGNS AND OTHER MATHEMATICAL SYMBOLS
\usepackage[italic,defaultmathsizes]{mathastext}
  % This makes the math font to be the default text font

% ESTRUCTURA DEL DOCUMENTO
% ========================

\usepackage[nottoc]{tocbibind} % ,notlot,notlof

% APÉNDICES
% ---------

\usepackage{appendix}


% GRÁFICOS Y COLORES
% ==================


\usepackage[pdftex]{graphicx}  % PDFTeX driver for graphicx.
\DeclareGraphicsRule{*}{mps}{*}{} % enables use of MetaPost graphics with pdflatex 
\usepackage{epstopdf}
\usepackage[dvipsnames]{xcolor}
\definecolor{azulVGB}{rgb}{0,0.33,0.58}%{0,0.33,0.67}
\definecolor{verdeVGB}{rgb}{0,0.58,0.33}%{0,0.67,0.33}
\definecolor{rojoVGB}{rgb}{0.58,0,0.33}%{0.67,0,0.33}
\definecolor{grisVGB}{rgb}{0.33,0.33,0.33}

% ENCABEZADOS Y PIES DE PÁGINA
% ============================

\RequirePackage{fancyhdr}

\pagestyle{fancy}
\fancyhead{}  % Limpia todo
\fancyfoot{}  % Limpia todo

\fancyfoot[LE,RO]{\color{black} \scriptsize{\textup{\thepage}}}
\fancyhead[LE]{\color{black}{\scriptsize{\textsc{\nouppercase{\leftmark}}}}}
\fancyhead[RO]{\color{black}{\scriptsize{\textsc{\nouppercase{\rightmark}}}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt} % Por defecto ya es así, pero que quede claro

\fancypagestyle{plain}{%
    \fancyhf{}  % Limpia todo
    \fancyfoot[LE,RO]{\color{black} \scriptsize{\textup{\thepage}}} 
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}}

\makeatletter
\DeclareRobustCommand{\notheader}[1]{\ifx\label\@gobble\dots\else#1\fi}
\makeatother


% TEOREMAS, DEFINICIONES, ENUMERACIONES, etc.
% ===========================================

\usepackage{amsthm} 

\newtheorem{teor}{Theorem}
\newtheorem{lema}{Lemma}
\newtheorem{prop}{Proposition}
\newtheorem{coro}{Corollary}
\newtheorem{conj}{Conjecture}


% TABLAS 
% ======

\usepackage{longtable} 
\usepackage{tabularx}  % en 'classicthesis-ldpkg' y [Thijs]
\newcolumntype{D}{>{\raggedleft \arraybackslash}X}
\newcolumntype{I}{>{\raggedright \arraybackslash}X}
\newcolumntype{Z}{>{\centering \arraybackslash}X}    
\usepackage{tabularray} % <----- ¡ NEW !
\UseTblrLibrary{booktabs}

% ALGORITMOS EN PSEUDOCÓDIGO 
% ==========================

\usepackage[english,ruled,vlined,linesnumberedhidden]{algorithm2e}

\newcommand{\mycomments}[1]{\textit{\footnotesize #1}}
\SetCommentSty{mycomments}

\SetKw{KwStep}{step}
\SetKw{KwOR}{or}
\SetKw{KwBreak}{break}
\SetKw{KwStop}{STOP}

% FIGURAS, ELEMENTOS FLOTANTES
% ============================

\RequirePackage[section,below]{placeins}

\usepackage{pdflscape}
\usepackage[subrefformat=parens]{subfig}  % Soporte para sub-figuras
\usepackage{keyval}  % Necesario para SUBFIG (creo)

% PIES DE FIGURAS, TABLAS, etc.
% =============================

\usepackage{caption} % Para \captionsetup

\captionsetup{width=0.75\textwidth}

\usepackage{comment}

% IDIOMAS (BABEL) 
% ===============

\usepackage[catalan,english,spanish]{babel} % french

%\decimalcomma (NO ES NECESARIO, ya es así por defecto)

% To restore the "." symbol that was changed by `mathastext`:
\AtBeginDocument{%
    \everymath\expandafter{\the\everymath\mathcode`.="8000 }%
    \everydisplay\expandafter{\the\everydisplay\mathcode`.="8000 }%
}%

% Redefinimos la manera de llamar a una 'table' en castellano.
% En lugar de 'cuadro' será "tabla" :
\addto\captionsspanish{\def\tablename{Tabla}}
% Lo mismo para "Índice de cuadros" :
\addto\captionsspanish{\def\listtablename{\'{I}ndice de tablas}}

% Personalización de los apéndices (se podría aprovechar para pasar de
% "apéndice" a "anexo", por ejemplo)  :
\renewcommand{\appendixname}{Anexo}      % Para el título de cada apéndice
\renewcommand{\appendixpagename}{Anexos} % Para la página que marca el inicio de los apéndices
\renewcommand{\appendixtocname}{Anexos}  % Para el índice general

\tolerance=5000 \hyphenpenalty=300 \pretolerance=400
% Para no separar tanto las palabras.

% BIBLIOGRAFÍA 
% ============

\usepackage[sectionbib,round,semicolon,authoryear]{natbib}

\renewcommand{\bibfont}{\small}

\providecommand{\urlprefix}{ }

\usepackage{chapterbib}


% HYPERREF Y OTROS ARREGLOS FINALES 
% =================================

\usepackage{pdfpages}

\usepackage[breaklinks=true,
pdftex,hyperfootnotes=false, % en false por usar 'footmisc'
pdfpagelabels]{hyperref}  % backref linktocpage pagebackref
\pdfcompresslevel=9
\pdfadjustspacing=1 
\hypersetup{pdfstartpage=1,pdfproducer={LaTeX with hyperref},%
    colorlinks=true, linkcolor=azulVGB, citecolor=verdeVGB,%
    filecolor=rojoVGB, urlcolor=rojoVGB,%
        pdfpagemode=UseOutlines, pdfpagelayout=SinglePage,%
        pdfhighlight=/N, pageanchor=true,%
        pdftoolbar=true, pdfmenubar=true, pdfstartview=FitH}
    
% ------------------------------------------------------------------------------

% ___________________________________________________________________________


\begin{document}
    
\frontmatter

\pagenumbering{roman}
\renewcommand{\thepage}{\textsc{\roman{page}}}

\pdfbookmark[0]{Anteportada (en blanco intencionadamente)}{anteportada}\thispagestyle{empty}

~ \\

\cleardoublepage

%\pdfbookmark[0]{Título}{titulo}\includepdf{portada.pdf} % <----------

%\include{./legal}


\cleardoublepage%
\pdfbookmark[0]{Índice general}{indice_general}%
\tableofcontents

\cleardoublepage%
\pdfbookmark[0]{Índice de figuras}{lista_figuras}%
\listoffigures

\cleardoublepage%
\pdfbookmark[0]{Índice de tablas}{lista_tablas}%
\listoftables

\mainmatter

\include{./cap_1}
\include{./cap_2}
\include{./cap_3}
\include{./cap_4}
\include{./cap_5}
\include{./cap_6}
\include{./cap_7}


% ___________________________________________________________________________


        
\end{document}

编辑

正如 @frabjous 所建议的(请参阅下面的评论),问题似乎是由这\AtBeginDocument句话引起的。这实际上是一个 hack,用于恢复西班牙语小数分隔符符号(逗号),该符号已被包改写为点mathastext(请参阅小数分隔符符号被“mathastext”覆盖)。

这是一个 MWE,正如下面的评论所要求的那样。

这个例子无法成功编译。但是,当删除句子时,它可以成功编译\AtBeginDocument(但数字内的逗号又变成了点)。

因此,这个问题已经得到部分回答,但如果能得到一个可行的例子就更好了,

  • mathastext
  • 逗号作为小数分隔符,以及
  • URL。

目前我只能同时拥有其中两个。

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[defaultfam,light,bold,proportional,lining]{montserrat}
  % Using Montserrat as our default font.
\usepackage[italic,defaultmathsizes]{mathastext}
  % This makes the math font to be the default text font.
\usepackage[spanish]{babel}
\decimalcomma % Not really needed, since this is the default option

% Restoring back comma as a decimal separator, which was overwritten by `mathastext`:
\AtBeginDocument{%
\everymath\expandafter{\the\everymath\mathcode`.="8000 }%
\everydisplay\expandafter{\the\everydisplay\mathcode`.="8000 }%
}%

\usepackage[breaklinks=true,
pdftex,hyperfootnotes=false, % en false por usar 'footmisc'
pdfpagelabels]{hyperref}

\begin{document}
Estos números son famosos:

$\pi = 3.14159\dots$

$e = 2.71828\dots$

$\varphi = 1.61803\dots$

Además,
%
\begin{equation}
    \pi = 3.14\dots = 4 \sum_{n=0}^{+\infty}{\frac{(-1)^n}{2n+1}} .
\end{equation}

Y esto es una URL: \url{https://tex.stackexchange.com/}.
\end{document}

答案1

嗯,hyperref 不喜欢这种数学代码的杂耍。您可以使用nopunctuationmathastext 选项。这样它就不会干扰小数点逗号,您的 hack 就没有必要了。

breaklinks 选项对 pdftex 没有任何作用,pdftex 选项是不需要的,而且自 2018 年以来 utf8 是默认选项,所以我将其删除了。

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[defaultfam,light,bold,proportional,lining]{montserrat}
  % Using Montserrat as our default font.
\usepackage[italic,defaultmathsizes,nopunctuation]{mathastext}
  % This makes the math font to be the default text font.
\usepackage[spanish]{babel}
\decimalcomma % Not really needed, since this is the default option

\usepackage[
hyperfootnotes=false, % en false por usar 'footmisc'
pdfpagelabels]{hyperref}

\begin{document}
Estos números son famosos:

$\pi = 3.14159\dots$

$e = 2.71828\dots$

$\varphi = 1.61803\dots$

Además,
%
\begin{equation}
    \pi = 3.14\dots = 4 \sum_{n=0}^{+\infty}{\frac{(-1)^n}{2n+1}} .
\end{equation}

Y esto es una URL: \url{https://tex.stackexchange.com/}.
\end{document}

答案2

你可以教导url.不应该受到特殊对待。

\documentclass[12pt]{article}

%\usepackage[utf8]{inputenc} % not needed
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}

% Using Montserrat as our default font.
\usepackage[defaultfam,light,bold,proportional,lining]{montserrat}
% This makes the math font to be the default text font.
\usepackage[italic,defaultmathsizes]{mathastext}

\usepackage[
  breaklinks=true,
  %pdftex, %<--- NO
  hyperfootnotes=false, % en false por usar 'footmisc'
  pdfpagelabels
]{hyperref}

%\decimalcomma % Not really needed, since this is the default option

% Restoring back comma as a decimal separator, which was overwritten by `mathastext`:
\makeatletter
\AtBeginDocument{%
  \everymath\expandafter{\the\everymath\mathcode`.="8000 }%
  \everydisplay\expandafter{\the\everydisplay\mathcode`.="8000 }%
  \addto\UrlSpecials{\do\.{\mathchar\es@period@code}}%
}
\makeatother

\begin{document}

Estos números son famosos:

$\pi = 3.14159\dots$

$e = 2.71828\dots$

$\varphi = 1.61803\dots$

Además,
\begin{equation}
    \pi = 3.14\dots = 4 \sum_{n=0}^{+\infty}{\frac{(-1)^n}{2n+1}} .
\end{equation}

Y esto es una URL: \url{https://tex.stackexchange.com/}.

\end{document}

在此处输入图片描述

相关内容