Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pre-defined macros and more options for LaTeX #100

Open
truefalsename opened this issue Mar 17, 2016 · 32 comments
Open

Support pre-defined macros and more options for LaTeX #100

truefalsename opened this issue Mar 17, 2016 · 32 comments

Comments

@truefalsename
Copy link

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.

@elizhenning
Copy link

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.

@truefalsename
Copy link
Author

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.

@abnerlee
Copy link
Contributor

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

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

\water
$$

@truefalsename
Copy link
Author

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.

@abnerlee
Copy link
Contributor

OK, I got your point.

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

@abnerlee abnerlee changed the title Question/suggestion about latex Support pre-defined macros for LaTeX Mar 22, 2016
@truefalsename
Copy link
Author

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.

@AlexPasternak
Copy link

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/

@truefalsename
Copy link
Author

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.

@JianCheng
Copy link

+1 needed

@dogfishbar
Copy link

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

@masonlr
Copy link

masonlr commented Feb 23, 2017

+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
Copy link

masonlr commented Feb 24, 2017

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

@dogfishbar
Copy link

dogfishbar commented Feb 24, 2017 via email

@dzackgarza
Copy link

dzackgarza commented Nov 5, 2017

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

@gandalfsaxe
Copy link

Why doesn't this work:

But this does:

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

@chaoxu
Copy link

chaoxu commented Jun 6, 2019

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

@eiis1000
Copy link

eiis1000 commented Sep 8, 2020

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

@eiis1000
Copy link

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

@eiis1000
Copy link

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
Copy link

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

@bloff
Copy link

bloff commented Oct 5, 2020

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.

@prossberg
Copy link

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

@marcusps
Copy link

marcusps commented Dec 16, 2020

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.

@Sam-OT
Copy link

Sam-OT commented May 11, 2021

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.

@masonlr
Copy link

masonlr commented May 12, 2021

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
Copy link

masonlr commented May 12, 2021

@Sam-OT you might be able to just paste the fragment above into that html file. Others seem to have done this, cf. #3856, but with a different window.html file.

@Sam-OT
Copy link

Sam-OT commented May 12, 2021

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

@dzackgarza
Copy link

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.

@prossberg
Copy link

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

@Sam-OT
Copy link

Sam-OT commented May 12, 2021

@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

@scruel
Copy link

scruel commented Oct 11, 2022

scruel/docsify-latex@04155df
@abnerlee This commit might will be helpful to do the pass options to MathJax job, consider conf.user.json already exists.

@abnerlee abnerlee changed the title Support pre-defined macros for LaTeX Support pre-defined macros and more options for LaTeX May 4, 2023
@CX330Blake
Copy link

+1, following. I want to import some Latex packages so that I could use \begin{proof}, \begin{document}, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests