Etoolbox's \ patchcmd không thể tìm thấy mẫu tìm kiếm do gói hyperref
Tôi sử dụng reportlớp học và tôi đã học được từ các câu hỏi khác trên trang web này (như Xóa khoảng cách giữa các số liệu mỗi chương trong LoF ) cách tôi có thể điều chỉnh khoảng cách giữa các số liệu mỗi chương trong LoF. Tôi muốn thay đổi truyền thống
\addtocontents{lof}{\protect\addvspace{10\p@}}
trong tệp report.cls tới
\addtocontents{lof}{\protect\addvspace{15\p@}} bằng cách sử dụng bản vá này:
\makeatletter
\patchcmd{\@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
Tuy nhiên, bằng cách phát hành, \tracingpatchestôi có thể thấy những điều sau:
[debug] analyzing '\@chapter'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ macro can be retokenized cleanly
[debug] -- search pattern not found in replacement text
Tôi có làm điều gì sai ? Tôi không hiểu tại sao \patchcmdkhông thể tìm thấy mã được chỉ định. Đối với bản ghi, có 3 bản vá khác trong tài liệu của tôi (không sửa đổi \@chapter) và chúng đều hoạt động tốt.
Chỉnh sửa: Trong khi chuẩn bị MWE, tôi nhận ra rằng gói hyperreflà thủ phạm, vì việc xóa nó sẽ giải quyết được vấn đề.
\documentclass[12pt,twoside,openright]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{etoolbox}
\usepackage[pdftex,colorlinks,linkcolor=blue,citecolor=red]{hyperref}
%----------------------- Patch -----------------------
\tracingpatches
\makeatletter
\patchcmd{\@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
%-----------------------------------------------------
\begin{document}
\listoffigures
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\appendix
\chapter{A chapter}
\addtocontents{lof}{\protect\addvspace{10pt}}%
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\end{document}
Có cách nào để sửa lỗi này ? Tôi cần phải tiếp tục tải hyperrefgói hàng.
Trả lời
hyperref phải xác định rất nhiều lệnh nội bộ để thực hiện công việc của nó.
Trong trường hợp này định nghĩa ban đầu của \@chapterđược lưu vào \Hy@org@chapterbằng cách hyperref, \@chaptersau đó được định nghĩa lại để làm một số liên kết và sau đó gọi \Hy@org@chapter.
Vì vậy, giải pháp ở đây là vá \Hy@org@chapterthay vì tải \@chapterkhi nào hyperref.
\documentclass[12pt,twoside,openright]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{etoolbox}
\usepackage[pdftex,colorlinks,linkcolor=blue,citecolor=red]{hyperref}
%----------------------- Patch -----------------------
\tracingpatches
\makeatletter
\patchcmd{\Hy@org@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
%-----------------------------------------------------
\begin{document}
\listoffigures
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\appendix
\chapter{A chapter}
\addtocontents{lof}{\protect\addvspace{10pt}}%
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\end{document}
cho
và
[debug] tracing \patchcmd on input line 16
[debug] analyzing '\Hy@org@chapter'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ macro can be retokenized cleanly
[debug] ++ search pattern found in replacement text
[debug] ++ patching possible
[debug] == retokenizing macro now
Ngoài ra, bạn có thể thử tải bản vá của mình trước khi hyperref áp dụng các định nghĩa lại của nó.
\documentclass[12pt,twoside,openright]{report}
\usepackage{etoolbox}
%----------------------- Patch -----------------------
\tracingpatches
\makeatletter
\patchcmd{\@chapter}%
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{\protect\addvspace{15\p@}}}% <replace>
{}{}% <success><failure>
\makeatother
%-----------------------------------------------------
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage[pdftex,colorlinks,linkcolor=blue,citecolor=red]{hyperref}
\begin{document}
\listoffigures
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\chapter{A chapter}
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\appendix
\chapter{A chapter}
\addtocontents{lof}{\protect\addvspace{10pt}}%
\begin{figure}\caption{A figure}\end{figure}
\begin{figure}\caption{A figure}\end{figure}
\end{document}
Cảm ơn David Carlisle đã gợi ý điều đó trong các ý kiến .