pdfescape
Provides essential string escaping and encoding functionality for handling special characters and strings in PDF output.
Overview
Implements critical text escaping features that are normally only available in pdfTeX, making them accessible in regular TeX or e-TeX environments. The package is particularly valuable when working with PDF-specific features or when precise control over character encoding is needed.
- Offers commands for hexadecimal encoding and decoding of strings
- Enables proper escaping of special characters in PDF strings and names
- Useful for creating PDF bookmarks, metadata, and other PDF-specific features that require properly encoded text
- Essential for developers creating packages that need to work with PDF features across different TeX engines
Getting Started
To use pdfescape
, include it in your document preamble:
\documentclass{article}
\usepackage{pdfescape}
This package implements pdfTeX's escape features using TeX or e-TeX, making these functions available even when not using pdfTeX or when using an older version of pdfTeX that doesn't provide these primitives.
Examples
Converting a string to hexadecimal representation for PDF compatibility.
Original string: \texttt{Hello World!}
Hexadecimal escaped: \texttt{\EdefEscapeHex{\temp}{Hello World!}\temp}
This is useful when you need to include special characters in PDF strings that might otherwise cause issues with PDF metadata or bookmarks.
Escaping strings for PDF bookmarks and metadata to ensure special characters are handled correctly.
\documentclass{article}
\usepackage{pdfescape}
\usepackage{hyperref}
\begin{document}
\section{Using EscapeString for bookmarks}
% Create a string with special characters that would cause problems in PDF bookmarks
\def\mystring{Symbols: $\alpha \beta \gamma$ \& \# \%}
% Use EscapeString to make it safe for PDF strings
\EdefEscapeString{\safebookmark}{\mystring}
% Now we can use it safely in PDF metadata
\pdfbookmark{\safebookmark}{bookmark1}
The original string with special characters: \mystring
The escaped version is used in the PDF bookmark.
\end{document}