Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

Request: Allow adding arbitrary anchors to be linked with `@ref`

Open anthony-wang opened this issue 7 years ago • 5 comments

My use case is that I generated thumbnails as previews for plot figures, and I'd like that these thumbnail images be cross-referenced with @ref or similar so that when clicked, we can jump to another section in the docs (e.g. to view the full-sized plot or the source code).

Currently, ![alt text](figure.png) inserts a figure and [Some-Header-Title](@ref) inserts a parsed cross-reference HTML link to the specified header anchor, and [text](URL) is a hyperlink, but I haven't been able to figure out a way to combine inserting the fig + a cross-referenced link. As far as I can tell, Documenter only allows @ref to headers.

Therefore, a way of specifying arbitrary anchors on any content so that we can @ref them elsewhere in the documentation would be nice!

A suggested design could be: [content](@anchor anchor-name) in the markdown, which is then outputted with <a> tags with id's in the HTML. Then these anchors can be referenced by using @ref.

(thanks to @mortenpi for the suggested design!)

anthony-wang avatar Jun 16 '18 09:06 anthony-wang

+1 for this, but shouldn't the syntax be [content](@id anchor-name) to be consistent with the one for naming headers?

ettersi avatar Oct 16 '22 04:10 ettersi

Yeah, re-using at-id makes sense to me. Currently, we're being extremely conservative about where we try to find at-ids (namely, only only within top-level headings), so generalizing it shouldn't be a problem.

I wonder how easy it is to introduce arbitrary anchors into LaTeX though. @odow, you don't happen to have any thoughts on this?

mortenpi avatar Oct 16 '22 22:10 mortenpi

I believe this should do the job? https://www.overleaf.com/learn/latex/Hyperlinks#Inserting_links_manually

ettersi avatar Oct 16 '22 23:10 ettersi

We already use a mix of hyper refs:

https://github.com/JuliaDocs/Documenter.jl/blob/998d26e568a20e3b1764d0c2cef30ebe4d2563ae/src/Writers/LaTeXWriter.jl#L317 https://github.com/JuliaDocs/Documenter.jl/blob/998d26e568a20e3b1764d0c2cef30ebe4d2563ae/src/Writers/LaTeXWriter.jl#L356

But yeah, some way of labeling and ref-ing to tables and figures would be useful.

odow avatar Oct 16 '22 23:10 odow

See also issue #2584 for a related feature request.

fingolfin avatar Oct 28 '25 13:10 fingolfin