TeXipedia

hopatch

Enables dynamic registration and application of patch code for LaTeX packages, either immediately or upon package loading.

Overview

Provides a flexible mechanism for applying modifications to existing LaTeX packages through a registration system. The functionality is particularly valuable for package maintenance and compatibility management.

  • Allows immediate patch application when target packages are already loaded
  • Stores patches for automatic application when packages load later
  • Useful for document-level package modifications without altering original package files
  • Commonly employed by package maintainers and advanced users who need to apply fixes or customizations to existing package behavior

Getting Started

To use hopatch, include it in your document preamble:

\documentclass{article}
\usepackage{hopatch}

This package is primarily intended for package authors or users who need to apply patches to existing packages. The main functionality is:

% Register a patch for a package
\hopatch{package}{patch code}

Examples

Using hopatch to apply a patch to a package after it's loaded.

\documentclass{article}
\usepackage{etoolbox}
\usepackage{lipsum}

% Apply a patch to redefine the lipsum command
\renewcommand{\lipsum}[1][]{\textbf{This is patched lipsum text.}}

\begin{document}
\section{Original vs Patched Lipsum}

The following text uses the patched version of lipsum:

\lipsum

As you can see, the original lipsum text has been replaced with our custom message.
\end{document}

Registering a patch for a package before it's loaded.

\documentclass{article}
\usepackage{etoolbox}
\usepackage{graphicx}

\AtBeginDocument{%
  \renewcommand{\includegraphics}[2][]{%
    \fbox{\textbf{[Image placeholder: #2]}}%
  }%
}

\begin{document}
\section{Patched Graphics Package}

The following image inclusion has been patched to show a placeholder instead:

\includegraphics{example-image}

This is useful for draft documents or when you want to customize package behavior.
\end{document}