typora-issues icon indicating copy to clipboard operation
typora-issues copied to clipboard

Support pre-defined macros and more options for LaTeX

Open truefalsename opened this issue 9 years ago • 32 comments

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.

truefalsename avatar Mar 17 '16 10:03 truefalsename

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.

elizhenning avatar Mar 19 '16 04:03 elizhenning

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.

truefalsename avatar Mar 21 '16 15:03 truefalsename

I think \newcommand and \def is supported, eg:

$$
\newcommand{\water}{H_{2}O}

\water
$$

abnerlee avatar Mar 22 '16 02:03 abnerlee

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.

truefalsename avatar Mar 22 '16 06:03 truefalsename

OK, I got your point.

Thanks for the suggestions. It's a good idea.

abnerlee avatar Mar 22 '16 06:03 abnerlee

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.

truefalsename avatar Mar 22 '16 14:03 truefalsename

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/

AlexPasternak avatar Mar 22 '16 14:03 AlexPasternak

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.

truefalsename avatar Mar 23 '16 07:03 truefalsename

+1 needed

JianCheng avatar Dec 11 '16 13:12 JianCheng

+1 : it would be really great to get access to latex packages!

dogfishbar avatar Jan 08 '17 13:01 dogfishbar

+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

masonlr avatar Feb 23 '17 04:02 masonlr

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, ""]
                }
}

masonlr avatar Feb 24 '17 00:02 masonlr

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 .

dogfishbar avatar Feb 24 '17 00:02 dogfishbar

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

dzackgarza avatar Nov 05 '17 03:11 dzackgarza

Why doesn't this work:

But this does:

..which leaves some unwanted empty space for the first math block.

gandalfsaxe avatar Mar 06 '18 08:03 gandalfsaxe

+1: This is in fact the only thing that is holding me back from switching to Typora.

chaoxu avatar Jun 06 '19 09:06 chaoxu

+1, if you had this feature I'd switch over with no hesitation.

eiis1000 avatar Sep 08 '20 14:09 eiis1000

Do you intend to add support for custom preambles and/or packages in the near future?

eiis1000 avatar Sep 17 '20 15:09 eiis1000

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.

eiis1000 avatar Sep 19 '20 01:09 eiis1000

Also, updating MathJax to v3 would solve this problem immediately along with various other improvements!

eiis1000 avatar Sep 21 '20 13:09 eiis1000

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.

bloff avatar Oct 05 '20 11:10 bloff

Will a feature with pre definable macros be added? Or is there already a way to do it?

prossberg avatar Nov 25 '20 15:11 prossberg

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.

marcusps avatar Dec 16 '20 04:12 marcusps

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, ""]
                }
}

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.

image

I only really want a few easy macros put in, so I'm happy to write them in as shown in the quoted comment.

Sam-OT avatar May 11 '21 15:05 Sam-OT

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>

...

masonlr avatar May 12 '21 00:05 masonlr

@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.

masonlr avatar May 12 '21 00:05 masonlr

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].

image

The precise location for me, on Windows 10, was C:\Program Files\Typora\resources\window.html

Sam-OT avatar May 12 '21 08:05 Sam-OT

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 avatar May 12 '21 17:05 dzackgarza

@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.

prossberg avatar May 12 '21 17:05 prossberg

@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

Sam-OT avatar May 12 '21 17:05 Sam-OT