Use latex math macro

andrewchengchou's Avatar

andrewchengchou

31 May, 2015 05:34 PM

I was trying to define a latex math macro throughout one markdown file. The latex macro is to define a matrix transpose:
\newcommand{\tr}{{\scriptscriptstyle\mathrm{T}}}

I managed to do it by adding the following scripts at the beginning of the markdown file.

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
  TeX: {
    Macros: {
      tr: "{\scriptscriptstyle\mathrm{T}}",
    }
  }
});
</script>
I can then use the command \tr throughout the markdown file. For example,
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
  TeX: {
    Macros: {
      tr: "{\scriptscriptstyle\mathrm{T}}",
    }
  }
});
</script>
The tranpose of a real matrix $A$ is denoted by $A^\tr$.

QUESTION: How can I make the above macro as a user default in marked 2 app? So I don't have to copy and paste the scripts for a new markdown document.

  1. Support Staff 1 Posted by Brett on 31 May, 2015 06:36 PM

    Brett's Avatar

    Under Style preferences, you'll see an "Additional MathJax Config"
    field. Add the part of your script that's inside the MathJax.Hub.Config
    object to that field and save:

    TeX: {
         Macros: {
    tr: "{\scriptscriptstyle\mathrm{T}}",
          }
    }

    -Brett

  2. Support Staff 2 Posted by Brett on 31 May, 2015 06:36 PM

    Brett's Avatar

    You may need the include the outer curly brackets around that, I can't
    recall offhand how I have that injected. Let me know if you have issues
    and I can dig back into it.

    -Brett

  3. 3 Posted by andrewchengchou on 31 May, 2015 11:23 PM

    andrewchengchou's Avatar

    I tried both

    TeX: { 
            Macros: { 
    tr: "{\scriptscriptstyle\mathrm{T}}", 
            } 
    }
    
    and
    {
      TeX: {
        Macros: {
          tr: "{\scriptscriptstyle\mathrm{T}}",
        }
      }
    }
    
    Neither works. And there was an error popped out. Error parsing additional mathjax configuration.
  4. Support Staff 4 Posted by Brett on 31 May, 2015 11:48 PM

    Brett's Avatar

    Ok, I dug into it further and I have an error in the parser that
    converts the string in the preferences into a config object for MathJax.
    I'll try to have this worked out for the next update. In the meantime,
    you could use the raw include syntax to put your macros into a separate
    file and include it in documents that need it:

    <<{filename.js}

    Let me know if that helps.

    Thanks,
    Brett

  5. 5 Posted by andrewchengchou on 01 Jun, 2015 12:15 AM

    andrewchengchou's Avatar

    Thanks Brett. Including the outer file works well. But there is one minor issue. Instead of saving the original script, I need to modify it slightly.
    ```
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
      TeX: {
        Macros: {
          tr: "{\\scriptscriptstyle\\mathrm{T}}",
        }
      }
    });
    </script>
    ```
    Note the double slash (`\\`) rather `\` in front of `scriptscriptstyle` and `mathrm`.

  6. Support Staff 6 Posted by Brett on 01 Jun, 2015 01:08 AM

    Brett's Avatar

    The code in your comment doesn't show a double slash. It's possible that somewhere along the line it's being unescaped, but Marked shouldn't be doing anything to it when using the raw syntax. I'll double check, though.

  7. 7 Posted by andrewchengchou on 01 Jun, 2015 03:19 AM

    andrewchengchou's Avatar

    I don't know why. My comment in the raw text form has double slashes. After formatting it in markdown, it became one slash. So I edited the comment so it is displayed in raw text.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac