Any chance of having an option to make asciiMath work?
I have a work around for this which is great but not pretty.
- I have downloaded
ASCIIMathML.js
from here and saved it on my machine at/my/local/path/to/
. -
Any note that I have where I want to add some math I simply add the following lines at the bottom of my note before typing:
<script type="text/javascript" src="/your/local/path/to/ASCIIMathML.js"></script>
<pre><script>mathcolor="Black"</script></pre>
The second line is only because the default colour for the math is blue.
-
Now I write any math that I want between the
amath
andendamath
tags.
Like so ...
amath
y = pi / x
endamath
And that's it.
But it would be nice if I could set this up in preferences, and didn't have to have the script lines at the end of my note.
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
Support Staff 1 Posted by Brett on 19 Jul, 2014 12:43 PM
I'd consider adding this to the preferences, but I'll need more than just one vote. If anyone else wants to see this, please comment here.
2 Posted by Mitchell on 03 Aug, 2014 12:19 AM
I would really like this. TeX math input takes a lot of keystrokes and it's hard to read and make changes to it. I would like a checkbox that allows me to enter math just as before (same delimiters, etc.) but parses it as AsciiMath rather than TeX.
Before:
$$V_\text{frustum}=\pi\int_0^h\left[R_1+(R_2-R_1)\frac{z}{h}\right]^2 dz$$
After:
$$V_"frustum" = pi int_0^h [R_1 + (R_2 - R_1)z/h]^2 dz$$
3 Posted by Stephen Thomas on 22 Aug, 2014 01:25 AM
+1 (more if it were permitted).
The lack of ASCIIMath support prevents me from using Marked, since most of the documents I'm currently writing include equations, and LaTeX is far too cumbersome to input by hand. I've had to resort to MathML (which isn't nearly as nice as ASCIIMath) but at least most Markdown editors (e.g Markdown Pro or MultiMarkdown Composer) pass it through unchanged to their previewers and Webkit renders it fine.
We'll have to see what Typed has up it's sleeve.
4 Posted by Stephen Thomas on 22 Aug, 2014 01:31 AM
As a followup, I note that the latest version MathJax.js supports ASCIIMath if configured appropriately. Since Marked already has an option to include MathJax, enabling this really should be pretty simple. Probably just configuring the appropriate MathJax options and defining the delimiters (since MathJax uses backticks by default). Send me a note if you want more explicit suggestions or a beta tester.
Support Staff 5 Posted by Brett on 22 Aug, 2014 02:54 AM
Do you have a pointer to the docs for ASCIIMath support in MathJax?
6 Posted by Stephen Thomas on 22 Aug, 2014 11:33 AM
Sure: MathJax AsciiMath Support
7 Posted by Stephen Thomas on 22 Aug, 2014 12:28 PM
You'll probably want to add a bit of code to disable markdown processing within the ASCIIMath delimiters. For example (using the backtick as a delimiter):
Gets turned into
And the added
<sup>
tags throw off the ASCIIMath processor.8 Posted by Stephen Thomas on 24 Aug, 2014 12:45 PM
As a bit of followup, and in hopes of helping folks out until there's full support for asciiiMath, it is possible to get Marked 2 to work with asciiMath with only a small bit of work. These steps are based on the excellent idea originally described by
m
above.First, you'll want to disable the built-in MathJax support. That's in two places in the app. In the Style preferences, in the Advanced section at the bottom of the window, make sure Enable MathJax is not checked.
Then, when exporting a document to HTML, make sure that Include MathJax CDN link is not checked.
Second, in the document that you want to use asciiMath, add the following line at the end.
Yes, this is adding back MathJax support (which we just removed in step 1), but it's doing so with a different configuration. The built-in configuration that Marked uses is
TeX-AMS-MML_HTMLorMML
and that configuration doesn't support asciiMath.Third, embed any asciiMath expressions within delimiters consisting of the backslash (
\
) followed by the back-tick (`
). The backslash before the back-tick is important; without it, Marked will treat the back-tick as a way to indicate inline code, as per the regular markdown syntax. Also, you have to escape any characters that are part of regular markdown within your asciiMath. That's mostly the caret (^
) and the underscore (_
). To escape those characters, just add a backslash in front of them. For example, the following standard asciiMath expression:can be included as
One caveat: You'll need an internet connection when viewing your document.
Support Staff 9 Posted by Brett on 24 Aug, 2014 12:47 PM
If that's all it takes, I can make that an option easily with the
built-in MathJax. I'm just ignorant about all of the configuration
options.
10 Posted by Mitchell on 24 Aug, 2014 12:58 PM
All you need to do is use
?config=AM_HTMLorMML
.Also, I would prefer to keep using dollar signs for consistency, because the back ticks are already used for code, and because using
\`
means the math markup will get parsed as Markdown. You can configured MathJax to use dollar signs with this:You can have multiple pairs of delimiters in that array if you wanted. The only problem is that the ASCIIMath configuration doesn't recognize display math. In my own setup, I use a regex to change
$$...$$
to<p class="display-math">$...$</p>
, and it works pretty well just with.display-math { text-align: center; }
.11 Posted by Stephen Thomas on 24 Aug, 2014 02:23 PM
As a bit of followup to Mitchell's suggestions:
If Marked provided the option to select the MathJax configuration (the value of the
config=
query parameter in the script URL), that would indeed be enough to get asciiMath working. The currently supported values for this query parameter can be found in the MathJax documentationThis change alone, however, will not be sufficient to allow delimiters other than back-ticks, as all of the pre-defined configurations use back-ticks. As Mitchel notes, to change the delimiter, Marked would have to forgo the simple query string configuration and add actual JavaScript code to set up MathJax. It might be tricky to expose appropriate settings of that configuration to Marked users.
Even if you change the delimiter to
$
, the math markup would still get parsed as markdown, so changing the delimiter doesn't really help much.Whatever the asciiMath delimiter is, it would be best if Marked could recognize it and disable markdown parsing of math markup. Without that support, you have to escape all the markdown characters in your math markup as noted in my comment above.
Personally, I don't have any particular preference for the specific delimiter, escaped back-ticks, dollar signs, whatever.
Without knowing anything about the Marked codebase, it's dangerous for me to do so, but it seems like the easiest approach would be:
a. Add an option to select the MathJax configuration from among the predefined values, and use the selected value as the query string parameter.
b. Automatically, or via a user option, disable markdown processing of text within a set of delimiters. The set of delimiters could initially be the escaped back-tick.
c. Enhance MathJax support to allow arbitrary configuration instead of the predefined query string values.
With the above approach, (a) would provide minimal asciiMath support without requiring users to add explicit scripts, (b) would allow use of math markup without requiring explicit escaping of markdown characters, and (c) would give users the option to customize MathJax support (including, but not limited to, delimiters).
Support Staff 12 Posted by Brett on 24 Aug, 2014 02:34 PM
It's a start...
I'm open to the idea of custom configs, probably via exposing the local.js file in the App Support folder. If you choose local in the dropdown and that file exists, it would use it. I already have it set up to take the selection in prefs and use it in the query string for both local preview and embedded export with the CDN.
13 Posted by Stephen Thomas on 24 Aug, 2014 02:59 PM
Now that is worth a bunch of five-star reviews!