# Tag Info

81

I would like to make my graphics homogeneous with my (LaTeX) document. That means that I would like to use the same font in the graphics (labels for axis etc) as the main text. I recently wrote a package, called MaTeX, to solve this exact problem. MaTeX makes it easy to compile short LaTeX snippets and embed them in Mathematica notebooks or graphics. Tip: ...

58

Here is my attempt to generate a pseudocode for algorithmicx package. Current features Functions (as SetDelayed) Set If with 2 and 3 arguments While Do (any number of variables of any type) New! Return Module, With, and Block CompoundExpression (;) Test functions (EvenQ, etc., and Not@EvenQ, etc.) New! Indentation Code ClearAll[pseudocode, pscd] ...

48

MaTeX is a package made exactly for this purpose. It can automatically compile small LaTeX snippets and import them as Mathematica graphics. It is described in detail in this other Mathematica.SE answer. A short tutorial is available here. Finally, to show what it can do, this is an example plot made with MaTeX labels (borrowed from the tutorial above, ...

41

I'll treat this question as being mainly about annotating graphics using LaTeX syntax. For that purpose, here is a template that you could use: Plot[Sin[x], {x, 0, 2 Pi}, Epilog -> Text[Style[ ToExpression["\\sin\\alpha", TeXForm, HoldForm], Large], {Pi, .5}]] However, there are several caveats because the ability of Mathematica to interpret $\... 39 Introduction Below I present usage of my CellsToTeX package. It provides functions for converting Mathematica cells to$\TeX$code compatible with$\TeX$package mmacells. Compilation of this$\TeX$code results in output resembling FrontEnd appearance of converted cells. Full capabilities of$\TeX$package are described in my post in "Fanciest way to ... 32 This is a good application for the highly underused Splice function which has been in Mathematica since version 1 (I don't recall it ever being used on this site). Create a file called main.mtex with the following text: \documentclass[preview,border=12pt,12pt]{standalone} \usepackage{amsmath} \def\f(#1){(#1)^2-5*(#1)+6} \begin{document} \section{Problem}... 32 You can use ToExpression. ToExpression["string", TeXForm, HoldForm] Paste your content inside quotes and click the button "yes", when the following dialog box opens, in order to escape backslashes and use them verbatim In your example, Mathematica 12.1 produces the following output 27 The following Mathematica construction translates to$\TeX$just fine: \left( \begin{array}{c} e_{\bot } \\ e_{\parallel } \\ \end{array} \right) Which looks like this in StackExchange's MathJax:$\left( \begin{array}{c} e_{\bot } \\ e_{\parallel } \\ \end{array} \right)$The key issue is to enter the initial Mathematica construction correctly. That ... 25 Why we're getting this buggy result In process of conversion to$\TeX\$, whenever Mathematica encounters "something delimited" i.e. RowBox with something surrounded with Strings matching: "(" | "[" | "$LeftModified]" | "\[LeftDoubleBracket]" | "{" | "\[Piecewise]" | "\[LeftFloor]" | "\[LeftCeiling]" | "\[LeftAngleBracket]" | "\[LeftSkeleton]" | "«" | "\[... 24 TeXForm is indeed your friend. It even gives you nicely formatted code: Table[RandomInteger[10], {3}, {4}] // TeXForm gives (* \left( \begin{array}{cccc} 9 & 5 & 10 & 9 \\ 6 & 10 & 3 & 9 \\ 9 & 5 & 9 & 7 \\ \end{array} \right) *) 24 I too had a need for a better syntax highlighting engine for Mathematica that can be used in different formats (so the javascript plugin is ruled out), so I wrote a better lexer and highlighter for Pygments than the one that ships with pygments. From the README: It can currently lex and highlight: All builtin functions in the System context ... 22 I am not willing to make MaTeX compatible with Mathematica 9 for the simple reason that it would create too much of a maintenance burden, and I already don't have time to properly respond to all support requests. If anyone is willing to hack MaTeX to work with Mathematica 9, here's what needs to be done. The primary reason why Mathematica 10 is required is ... 20 You can match formatting between Mathematica figures and LaTeX using a small package I just wrote for using LaTeX-snippets in Mathematica: MaTeX. Here's an example: <<MaTeX Plot[Sin[z], {z, -2 Pi, 2 Pi}, Frame -> True, FrameStyle -> BlackFrame, FrameLabel -> (MaTeX[#, Magnification -> 20/12] &) /@ {"z", "a(z) = \\sin z"}, ... 19 Since no one dares an answer, let me make some statements that you probably won't like since you seem keen to switch to Mathematica. I don't think this is a good idea. It is just not the right tool for this. My background is academic, I'm using Mathematica on a daily basis and I love it. For writing I'm using LaTeX for manuscripts and persistent documents, ... 15 Probably the easiest solution here is to use Format[x[arg_],TraditionalForm]:=Subscript[x, arg] This makes sure that the subscript form is used when the display is in TraditionalForm, which is also an intermediate step in creating TeXForm. Then you get for example 1+x[13]//TeXForm x_{13}+1 The Format can't be specified directly for TeXForm because ... 14 Here's a way that I find clear: Make sure i and n have no value: i=.; n=.. Generate a list of the held sum expressions, taking care to make the exponent go away from i^1. list = Table[With[{e = i^k}, HoldForm[Sum[e, {i, 1, n}]]], {k, 5}] Use ReleaseHold to make a table of results: TeXForm@TableForm[# == ReleaseHold[#] & /@ list]  \begin{... 14 What Format does Role of Format, as I understand it, is to set appropriate transformation rules. One can check those rules using FormatValues function: Format[x, TeXForm] = "{\\bf x}"; FormatValues[x] // FullForm (* List[RuleDelayed[HoldPattern[Format[x, TeXForm]], "{\\bf x}"]] *) One can also see those rules by inspecting symbol for which rules where set:... 14 This is not answer, but an extended comment that displays a graphic. The code you post in your question does not work in any recent version of Mathematica. It is syntactically and semantically incorrect. The following modified code does work. My question is: does it produce the plot you want to translate into LaTeX? rose[x_, theta_] := Module[ {... 14 You could use my TeXUtilities package: Import@"https://raw.githubusercontent.com/jkuczm/MathematicaTeXUtilities/master/NoInstall.m" Unprotect[FresnelC, CosIntegral]; Format[FresnelC@x_, TeXForm] := TeXVerbatim["\\operatorname{FresnelC}"]@x Format[CosIntegral@x_, TeXForm] := TeXVerbatim["\\operatorname{CosIntegral}"]@x (* Move TeXForm format to begining of ... 13 Here is a start (adjusted based on Szabolcs's statement that Row and TeXForm don't work together in v9): Clear[n] # == ReleaseHold[#] & /@ Array[HoldForm[Sum[i^#, {i, 1, n}]] &, 5] // Column // TeXForm \begin{array}{l} \sum _{i=1}^n i^1=\frac{1}{2} n (n+1) \\ \sum _{i=1}^n i^2=\frac{1}{6} n (n+1) (2 n+1) \\ \sum _{i=1}^n i^3=\frac{1}{4} n^2 ... 13 To get syntax highlighting for Mathematica in a latex code listing, try this: \usepackage{listings} \usepackage{color} \definecolor{listinggray}{gray}{0.9} \definecolor{graphgray}{gray}{0.7} \definecolor{blue}{rgb}{0,0,1} \definecolor{mygreen}{rgb}{0,0.6,0} \definecolor{mygray}{rgb}{0.5,0.5,0.5} \definecolor{mymauve}{rgb}{0.58,0,0.82} % define a custom ... 13 Unfortunately, the Mathematica's Copy As > LaTeX command is not (as you'd expect) a command that copies the selected expressions as LaTeX. Instead, it performs additional reformatting that can only be avoided by changing behavior of the relevant built-in function with: SystemFEDumpCopyAsTeXMakeBoxes = #& Details Why copied boxes are reformatted ... 13 content = WolframAlpha["integrate (sin(x))^4 dx", {{"IndefiniteIntegral", 2}, "Content"}, PodStates -> {"IndefiniteIntegral__Step-by-step solution"}][[1]]; BoxFormUseTemplateSlotSequenceForRow = False; TeXForm[Column@(MakeExpression[content //. StyleBox[a_, ___] :> a, StandardForm] /. {{{a_}, {b_, c___}} :> Column[{HoldForm[a], ... 12 Endorsing Szabolcs' excellent MaTeX package as a way to manage \LaTeX in Mathematica but with an addition that for me at least has removed the significant irritant of having to escape backslashes in strings. For example, given some previous \LaTeX "\tilde{x}=\begin{cases} (\frac{n+1}{2}) \text{th term} & \text{n odd} \\ ((\frac{n}{2}) \text{... 12 Caveat: Since this uses hidden, undocumented functions, it will probably break at some point in the future. Also, I do not have any knowledge of how these functions work, except guesses from observed behavior. Some information is available via Information. Under the hood of TexForm is ConvertTeXExpressionToTeX, which in turn calls ConvertTeXBoxesToTeX ... 12 The same sizes show up using pure Latex. \documentclass[11pt]{article} \begin{document} \Huge \[ \sqrt{\phantom{a^2}b}$ $\sqrt{a^2b}$ \end{document} Gives (compiled with pdflatex) And this is inside Mathematica: I do not see any difference. But I think your question is really about Latex itself and not Matex, which just compiles using Latex. ...

11

As explained in the section tutorial/CitationManagement you need to have EndNote or BibTeX for managing your citations. Interaction with both is covered in this tutorial. Below is the result I obtained using the sample BiBTeX file downloaded here. Don't forget to work in a cell with the Text style (Alt-7 on Windows) when you use this, otherwise the ...

11

There are a few ways to do this. The easiest is probably the switch off the script level changes that are taking place by selecting the cell bracket and setting AllowScriptLevelChange->False in the options inspector: For more subtle tweeking you need to leave AllowScriptLevelChange->True and adjust ScriptSizeMultipliers. For example with ...

11

It can be traced that, in minimal example from question, following definition of SystemConvertTeXFormDumpmaketex function is used: SystemConvertTeXFormDumpmaketex[str_String?SystemConvertCommonDumpEmbeddedStringWithLinearSyntaxQ] := ( SystemConvertCommonDumpDebugPrint["------------------------------------"]; SystemConvertCommonDump...

11

This answer has two proposed solutions one with a dedicated parser the other using conversion to JSON. The programming of the JSON conversion happened three times faster. (But it was also done earlier in the day when I was also properly caffeinated...) Making a dedicated parser We can make a dedicated parser in a manner similar to the approach explained in ...

Only top voted, non community-wiki answers of a minimum length are eligible