Skip to content

General support for references to the name of a Section/Chapter/etc. rather than its number. #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tracked by #4944
jjallaire opened this issue Jun 21, 2022 Discussed in #1178 · 3 comments
Open
Tracked by #4944
Assignees
Labels
crossref enhancement New feature or request triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone.
Milestone

Comments

@jjallaire
Copy link
Collaborator

Discussed in #1178

Originally posted by fuhrmanator June 18, 2022
In books it is very useful to refer to a section by its name. The Quarto documentation does this, e.g. the link to "Cross references" on this line:

https://github.com/quarto-dev/quarto-web/blob/eed8baacea8448cd2ec60e34250ad2215de6831f/docs/authoring/figures.qmd#L25

But it's done with a hyperlink to an absolute HTML page.

Another example is within a page:

https://github.com/quarto-dev/quarto-web/blob/eed8baacea8448cd2ec60e34250ad2215de6831f/docs/authoring/cross-references.qmd#L26

There's an anchor generated through ## Options {#options}. It seems to be HTML-specific.

In LaTeX, it's done by \nameref{sec-blahblah} and I see that quarto supports this for PDF output.

Are there plans to make this work with @sec-blahblah for other render destinations (e.g. html)? I'm thinking something like [caption@sec-blahblah] as a general solution.

@jjallaire jjallaire added this to the 1.0 milestone Jun 21, 2022
@jjallaire jjallaire self-assigned this Jun 21, 2022
@jjallaire
Copy link
Collaborator Author

We don't currently have a way to inject section names directly into references to them however we will definitely consider this for a future release! Note that the only difference I currently see in HTML and PDF output is the placement of the hyperlink. e.g. for this source code:

---
title: "section-names"
number-sections: true
---

## Quarto {#sec-quarto}

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

See @sec-quarto.

HTML output looks like this:

Screen Shot 2022-06-21 at 4 10 55 PM

and PDF output looks like this:

Screen Shot 2022-06-21 at 4 11 16 PM

@jjallaire jjallaire modified the milestones: 1.0, Future Jun 21, 2022
@fuhrmanator
Copy link
Contributor

Thanks for the hint about an HTML and PDF solution.

@mcanouil mcanouil added crossref triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. labels Jul 7, 2023
@mcanouil mcanouil assigned cscheid and unassigned jjallaire Jul 7, 2023
@mcanouil mcanouil mentioned this issue Jul 7, 2023
62 tasks
@cscheid cscheid modified the milestones: Future, v1.5 Dec 1, 2023
@cscheid cscheid modified the milestones: v1.5, Future Mar 1, 2024
@wklimowicz
Copy link

wklimowicz commented Apr 6, 2024

Not sure whether this is in scope, but would be great to have native quarto support for making the LaTeX reference become a hyperlink to the entire prefix, not just the number (so that the hyperlink is Figure 1, not just the 1). The easy workaround right now is just to use \autoref{fig-foo} rather than @fig-foo. I tried looking at a lua filter to do this but because of the way citeproc works this isn't trivial.

EDIT: With some playing around I've managed to get a workaround pandoc filter which replaces all instances of the citeproc citation with \autoref, so the whole word is highlighted.

-- Pandoc filter to replace citations with \autoref{}
function replace_citations(cite)
    local replace_envs = { "fig", "tbl" }
    if quarto.doc.is_format("latex") then
        for _, citation in ipairs(cite.citations) do
            local id = citation.id
            for _, prefix in ipairs(replace_envs) do
                if id and id:match("^" .. prefix .. "%-") then
                    return pandoc.RawInline("latex", "\\autoref{" .. id .. "}")
                end
            end
        end
    end
    return cite
end

return {
    Cite = replace_citations
}

EDIT2: This works for tables and figures, but doesn't work for equations (with \autoref they show up as section 1 rather than Equation 1). This is because quarto (or rather pandoc?) creates a \phantomsection around the equation, so this in quarto:

$$
y = mx + c
$$ {#eq-foo}

becomes this in LaTeX:

\begin{equation}\phantomsection\label{eq-foo}{
y = mx + c
}\end{equation}

Once again, easy workaround is just to use raw latex for now with \begin{equation} \label{....

@mcanouil mcanouil added the enhancement New feature or request label Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crossref enhancement New feature or request triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone.
Projects
None yet
Development

No branches or pull requests

5 participants