add tag
Trevor
I have a Latex document, inside of which I have figures written in Metapost (included using the `luamplib` package). I would like to include references to parts of the Latex document (e.g., sections) within the Metapost code. I have tried to do this, but unfortunately the links positions end up either not matching the text position, or the links are not created at all.

Here is a minimal working example (compiled with `lualatex`). 
```
\documentclass[10pt]{article}

\usepackage{hyperref}
\usepackage{luamplib}

\mplibtextextlabel{enable}

\begin{document}

\section{My section} \label{sec:my_section}

Hi

\begin{mplibcode}
beginfig(1);
label(btex \ref{sec:my_section} etex, (14,6)); % this creates a link in the wrong location
label(btex \ref{sec:my_section} etex, (39,6)); % this does not create a link at all
endfig;
\end{mplibcode}

\end{document}
```

An snippet image of the resulting document is shown below. The first `label()` command creates a "1" (the leftmost "1") and a link (the red box), but the positions don't match. The second `label()` command creates a "1" (the rightmost "1"), but does not create a link at all.

![Screenshot From 2026-03-31 00-53-04.png](/image?hash=3cb2ac7ce800b4dbaf484839c493df0ef3e96af94cc4284201e378f1604890bf)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.