typora-issues
typora-issues copied to clipboard
Support pre-defined macros and more options for LaTeX
Hello, I started to use Typora for writing down my notes and I really like it!
I would like to know if it is possible to use some extra latex packages via \usepackage{smt here}. I tried to include these commands at the code level but they do not seem to work.
If it was possible, it could be great to have the option to edit the standard 'latex preamble' via a menu, so that one could specify the extra packages that he/she intends to use, custom command, renewed commands and so on while keeping a neat look for the document being edited.
Typora uses MathJax for real-time rendering, so there's no preamble to deal with (thank goodness). I personally would like to see XyJax, but that's really up to the XyJax dev. If you want a similar WYSIWYG interface that you can use your own preamble with, try LyX. The LibreOffice TeXMaths plugin also approximates real-time rendering, but it hasn't been updated in a while.
Alright, no extra packages. Still it would be nice if it could be possible to configure the underneath MathJax engine to include custom latex macros defined by \newcommand , \def etc. If I am not mistaken, these can be included in the MathJax configuration file.
I think \newcommand and \def is supported, eg:
$$
\newcommand{\water}{H_{2}O}
\water
$$
Yes, they are supported but, if you want to use the corresponding macros, you need to include them in every document you edit. It would we nice if one could specify these things once and for all in a sort of 'preamble' accessible via menu. The documents would look neater this way.
OK, I got your point.
Thanks for the suggestions. It's a good idea.
One last thing, it could be great also if, once in math mode, common environments and commands could be triggered by some key shortcut. For instance eq+tab for \begin{equation} \end{equation} or ali+tab for the align environment.
That seems like something many 3rd party applications could take care of, triggering actions or pasting in text based on keyboard shortcuts. E.g., https://smilesoftware.com/textexpander or https://www.keyboardmaestro.com/main/
Sure, however it could be nice to have a MathJax menu containing the option for a custom 'preamble', like I mentioned before, and the most common Mathjax commands and macros with the relative keybord shortcuts. This could improve the usability of Typora for people that are not familiar with Latex/MathJax.
+1 needed
+1 : it would be really great to get access to latex packages!
+1 : this would be possible if a mathjax config file was exposed to the user. See http://docs.mathjax.org/en/latest/tex.html#defining-tex-macros and http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-extensions
Yes, they are supported but, if you want to use the corresponding macros, you need to include them in every document you edit. It would we nice if one could specify these things once and for all in a sort of 'preamble' accessible via menu. The documents would look neater this way.
For what it's worth, I've started adding the common tex newcommands that I use by editing MathJax.Hub.Config in /Applications/Typora.app/Contents/Resources/TypeMark/index.html.
For example, to add the example commands described in the mathjax documentation (http://docs.mathjax.org/en/latest/tex.html#defining-tex-macros), use:
TeX: {
extensions: ["noUndefined.js", "autoload-all.js", "AMSmath.js", "AMSsymbols.js", "mhchem.js"],
Macros: {
RR: "{\\bf R}",
bold: ["{\\bf #1}",1],
Abs: ['\\left\\lvert #2 \\right\\rvert_{\\text{#1}}', 2, ""]
}
}
Thank you, I don't know if you got this, but thanks, I'm going to give that a try. Best, Bob Muller
On Thu, Feb 23, 2017 at 7:48 PM, masonlr [email protected] wrote:
Yes, they are supported but, if you want to use the corresponding macros, you need to include them in every document you edit. It would we nice if one could specify these things once and for all in a sort of 'preamble' accessible via menu. The documents would look neater this way.
For what it's worth, I've started adding the common tex newcommands that I use by editing MathJax.Hub.Config in /Applications/Typora.app/ Contents/Resources/TypeMark/index.html.
For example, to add the example commands described in the mathjax documentation (http://docs.mathjax.org/en/latest/tex.html#defining-tex- macros), use:
TeX: { extensions: ["noUndefined.js", "autoload-all.js", "AMSmath.js", "AMSsymbols.js", "mhchem.js"], Macros: { RR: "{\bf R}", bold: ["{\bf #1}",1], Abs: ['\left\lvert #2 \right\rvert_{\text{#1}}', 2, ""] } }
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/typora/typora-issues/issues/100#issuecomment-282169741, or mute the thread https://github.com/notifications/unsubscribe-auth/ABtjc9l2b7zuHNV66oA46pbxwHE26Gl0ks5rfijfgaJpZM4HyzQr .
One thought - is there any way to expose this functionality as a text box in the preferences menu that just gets injected into the index.html file mentioned above?
Edit: Or perhaps this alternative: http://docs.mathjax.org/en/latest/configuration.html#using-a-local-configuration-file-with-a-cdn
Why doesn't this work:

But this does:

..which leaves some unwanted empty space for the first math block.
+1: This is in fact the only thing that is holding me back from switching to Typora.
+1, if you had this feature I'd switch over with no hesitation.
Do you intend to add support for custom preambles and/or packages in the near future?
For anyone reading this issue, I managed to shove the physics.js package into Typora in #3856. Take a look there if you're interested to see how I did it.
Also, updating MathJax to v3 would solve this problem immediately along with various other improvements!
This would be wonderful. I'm used to typing all sorts of macros in my latex work. E.g. \eps is \varepsilon etc. The lack of predefined macros really breaks my flow.
Will a feature with pre definable macros be added? Or is there already a way to do it?
Since it seems like the MathJax way to pre-define macros and point to extensions is to provide a custom MathJax.Hub.Config, as @masonlr indicated, maybe conf/conf.user.json can take in a parameter that points to the the user's custom MathJax.Hub.Config? And maybe that parameter is exposed through the preferences UI?
Editing window.html is a painful hack.
For what it's worth, I've started adding the common tex newcommands that I use by editing
MathJax.Hub.Configin/Applications/Typora.app/Contents/Resources/TypeMark/index.html.For example, to add the example commands described in the mathjax documentation (http://docs.mathjax.org/en/latest/tex.html#defining-tex-macros), use:
TeX: { extensions: ["noUndefined.js", "autoload-all.js", "AMSmath.js", "AMSsymbols.js", "mhchem.js"], Macros: { RR: "{\\bf R}", bold: ["{\\bf #1}",1], Abs: ['\\left\\lvert #2 \\right\\rvert_{\\text{#1}}', 2, ""] } }
I know this is a fairly old post, but my index.html doesn't look anything like the above. There is no mention of MathJax.Hub.Config I can't find any files like AMSmath.js anywhere in my install---either Program Files or AppData.

I only really want a few easy macros put in, so I'm happy to write them in as shown in the quoted comment.
On MacOS /Applications/Typora.app/Contents/Resources/TypeMark/setting-dist/index.html still looks like this:
...
171 <script type="text/x-mathjax-config" aria-hidden="true" >
172 MathJax.Hub.Config({
173 skipStartupTypeset: true,
174 jax: ["input/TeX", "output/SVG"],
175 extensions: ["tex2jax.js", "toMathML.js"],
176 TeX: {
177 extensions: ["noUndefined.js", "autoload-all.js", "AMSmath.js", "AMSsym bols.js", "mediawiki-texvc.js"],
178 mhchem: { legacy: false },
179 MAXBUFFER: 10*1024
180 },
181 SVG: {
182 useGlobalCache: false,
183 merrorStyle: {
184 fontSize:"90%", color:"red", background:"",
185 border: "1px solid red", padding:"2px"
186 },
187 scale: 100,
188 minScaleAdjust: 80,
189 blacker: 0,
190 matchFontHeight: false,
191 undefinedFamily: "STIXGeneral, 'PingFang SC', serif"
192 },
193 showProcessingMessages: false,
194 tex2jax: {
195 displayMath: [['$$\n', '\n$$'], ['$$\r\n', '\r\n$$']],
196 inlineMath: [ ['$','$'], ['$$', '$$']],
197 processEscapes: true,
198 preview: "none",
199 skipTags: ["script","noscript","style","textarea","pre","code", "span"] ,
200 processClass: "md-inline-math|inline-math-export-jax|math-in-toc"
201 },
202 menuSettings: {
203 inTabOrder: false
204 },
205 showMathMenu: false,
206 positionToHash: false
207 });
208 MathJax.Hub.processSectionDelay = 0;
209 MathJax.Hub.processUpdateTime = 25;
210 MathJax.Hub.processUpdateDelay = 0;
211 MathJax.Hub.Queue(["setRenderer", MathJax.Hub, "SVG"]);
212 MathJax.Hub.Register.StartupHook("TeX autoload-all Ready", function () {
213 var MACROS = MathJax.InputJax.TeX.Definitions.macros;
214 MACROS.color = "Color";
215 delete MACROS.colorbox;
216 delete MACROS.fcolorbox;
217 });
218 </script>
...
@Sam-OT you might be able to just paste the fragment above into that html file. Others seem to have done this, cf. https://github.com/typora/typora-issues/issues/3856, but with a different window.html file.
Thanks, @masonlr, for the suggestion. I looked in the window.html file and it seems that basically everything you have in your index file is there in the window one. I added the bit that I highlighted and it seems to work. Both simply macros like eps: "{\\varepsilon}" and more complicated ones like Quad: ["{\\quad #1 \\quad}", 1].

The precise location for me, on Windows 10, was C:\Program Files\Typora\resources\window.html
Just as a heads up, modifying this HTML file directly can be problematic! For me, it seems to be overwritten any time there is an update.
@dzackgarza It is usually overwritten with every update. Which is why I have just resorted to using AutoHotkey for the few makros that I use in Typora.
@dzackgarza @prossberg Thanks for the comment. Perhaps the best thing to do, then, is to have a separate text file with all the macros in, then copy and paste on update. There aren't updates super often, so not so much of an issue. AutoHotKey also seems like a good option