Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • M MathJax
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 304
    • Issues 304
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • MathJax
  • MathJax
  • Issues
  • #2565
Closed
Open
Issue created Nov 05, 2020 by Administrator@rootContributor

A `\#` in the first argument of `\href` produces `/#` instead of `#`

Created by: pdmosses

Issue Summary

To define a macro \mylink with target id as parameter, such that \mylink{a} expands to \href{#a}{a}, the use of # in the macro definition needs to be escaped, to avoid ambiguity with LaTeX parameter references such as #1 (and potentially ##1 for nested macros).

Using \# works in a macro definition in LaTeX (when using the hyperref package):

\newcommand{\mylink}[1]{\href{\##1}{#1}}

but the same definition does not give the expected result in MathJax.

Steps to Reproduce:

  1. This is the first step
$$
\newcommand{\mylink}[1]{\href{\##1}{#1}}
$$

Target math `\cssId{a}{A}`
$$
\cssId{a}{A}
$$

`\href{#a}{b}` gives a correct hyperlink to `#a`:

$$
\href{#a}{b}
$$

`\mylink{a}` gives an incorrect link to `localhost:4000/#a`:

$$
\mylink{a}
$$
  1. This is the second step

Check that the link to the target from b is correct, and the link from a is broken.

I would expect MathJax to follow LaTeX by allowing the use of \# for # in the URL argument of \href in a macro definition. MathJax accepts the use of \#, but does not interpret it as # in the URL argument of \href.

Technical details:

  • MathJax Version: 3.1.2
  • Client OS: macOS 10.15.7
  • Browser: Safari 14.0
  • Framework: Jekyll 4.1.1, using MathJax inside kramdown math blocks $$...$$

Supporting information:

  • Include the MathJax configuration you are using, and the script tag that loads MathJax itself.
  <script>
    MathJax = { 
      tex: { 
        tags: 'ams',
        packages: {'[+]': ['textmacros']}
      },
      svg: { 
        fontCache: 'global', 
        displayAlign: 'left', 
        displayIndent: '2em',
        mtextInheritFont: true
      },
      loader: {
        load: ['[tex]/textmacros']
      }
    };
  </script>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
  <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>

I am a new user of MathJax. I am experimenting with using MathJax in the Jekyll theme Just the Docs.

P.S. Here is the HTML generated by Jekyll/kramdown from the example in step 1 above:

\[\newcommand{\mylink}[1]{\href{\##1}{#1}}\]
<p>Target math <code class="language-plaintext highlighter-rouge">\cssId{a}{A}</code>
\(\cssId{a}{A}\)</p>
<p><code class="language-plaintext highlighter-rouge">\href{#a}{b}</code> gives a correct hyperlink to <code class="language-plaintext highlighter-rouge">#a</code>:</p>
\[\href{#a}{b}\]
<p><code class="language-plaintext highlighter-rouge">\mylink{a}</code> gives an incorrect link to <code class="language-plaintext highlighter-rouge">localhost:4000/#a</code>:</p>
\[\mylink{a}\]
Assignee
Assign to
Time tracking