Extract links in PDF graphics for inclusion in LaTeX documents
Project description
To include fancy graphics (say a diagram) in your LaTeX document, a common process is to design the diagram using your favorite graphics designer program, to export the figure as a PDF graphic, and to use:
\includegraphics[width=10cm]{my_figure}
And it works great. Until you’d like to have figures with clickable links. You might even want to have links in your diagram to within the document—maybe a clickable link to a document section, equation, or an item in your bibliography.
The ltxpdflinks tool provides a simple solution to include a PDF with its links. It includes ways to encode links to within the document, like you’d obtain with \ref and \cite in LaTeX.
Quick Start
To get started:
Install ltxpdflinks:
pip3 install ltxpdflinks
Download the phflplx.sty file here:
To compile your document:
Drop the file phflplx.sty in the same folder as your latex source file, and add to your document preamble:
\usepackage{phflplx} \DeclareGraphicsExtensions{.lplx,.pdf}
[I’m assuming you’re loading the graphicx (or alternatively graphics) and the hyperref packages, too.]
Note: If you’d like to include also other file types in your document (e.g., .png, .jpeg, etc.), you need to add them to the \DeclareGraphicsExtensions argument, too. See doc for the graphicx package.
Run the ltxpdflinks command-line program for all your PDF files that contain links:
> ltxpdflinks myfigure1.pdf
Compile your LaTeX document as usual.
How to include links to other parts of the LaTeX document:
When creating your figure in your favorite drawing software, create a “web hyperlink” with an URL of the following form:
latexref://<type-of-reference>/<reference-target>
For a link to a section, equation, etc. (when you’d use \ref / \autoref / \cref in LaTeX), use latexref://ref/<label-target> where you replace <label-target> by the LaTeX label of the object you’re referencing (the argument of the \label{...} command in LaTeX).
For a link to a bibliographic reference entry (as in \cite{...}), use latexref://cite/<bibtex-key>, where you replace <bibtex-key> by the bibliographic reference key you’d like to refer to (the argument you’d use to the \cite{...} command).
These special URL links are automatically converted to LaTeX references by the ltxpdflinks utility and the phflplx package.
Features
Special link conversions:
latexref://ref/XXXXXX → link to XXXXXX label as via \ref{XXXXXX} latexref://cite/XXXXXX → link to XXXXXX citation as via \cite{XXXXXX}
(In the future I’ll probably add ways to plug in custom link conversions. The code is extendible & you can add them yourself already if you invoke ltxpdflinks via your own python script.)
Full support for rotation, scaling and clipping via options to \includegraphics[...]{...}
Links use the format defined in the LaTeX document (colors & border relevant for link type URL/internal reference/citation as specified via the hyperref package.)
Simple Python implementation which you can use via your own custom script if you’d like to add link conversions or customize the process in any way.
To get started:
import ltxpdflinks extractor = ltxpdflinks.PdfGraphicLinksExtractor(fname) extracted = extractor.extractGraphicLinks() converter = ltxpdflinks.LatexRefsLinkConverter() converter.convertLinks(extracted) lplxexporter = ltxpdflinks.LplxPictureEnvExporter() lplx_content = lplxexporter.export(extracted) with open('my_ouput_file_will_be_overwritten.lplx', 'w') as foutput: foutput.write(lplx_content)
Planned future improvements
Support the possibility (as an opt-in option) to preserve link styling (border, color, etc.) instead if using the document links style?
Support for internal annotations within the PDF graphic (from one part of the graphic to another)?
Support for other types of annotations?
Support for generation of .pax files for use with the pax LaTeX package instead?
Existing alternatives
You can also directly create your diagrams natively in LaTeX using TiKZ. I prefer to prepare diagrams with drawing software, but that’s a personal preference.
The pax LaTeX package and associated utility also includes PDF links and annotations using a similar philosophy; it also provides a separate command-line tool to process PDF files before inclusion.
As far as I could tell, pax supports more PDF annotations and preserves link styles. It doesn’t seem to provide link conversion to LaTeX references and citations for internal links. It also doesn’t seem to fully support rotation and clipping via options to \includegraphics. The command-line utility is written in Java.
This option has been around for a while, so it might definitely be more stable!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ltxpdflinks-0.2.0.tar.gz
.
File metadata
- Download URL: ltxpdflinks-0.2.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeaa4074e9862e43b5831b098777f29c183b84b4501b0d0a6b89d5b9321506a2 |
|
MD5 | 0e25292a373a9636a5d2825afab3613b |
|
BLAKE2b-256 | aca015a5eb9321d567f936d9d9bb575121c7f20b841608a607718d979aeaf117 |