3

How can I insert this Mathematica plot in LaTex as a figure?

enter image description here

MWE:

\documentclass[12pt, a4paper]{report}
    \usepackage{amsfonts, graphicx, verbatim, mathtools,amssymb, amsthm, mathrsfs}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\usepackage{epstopdf}
\usepackage{latexalpha2}
\usepackage{graphicx}

\begin{document}

\begin{figure} \wolframgraphics{Plot[{Log[ x], 1(x - 1), 1.5(x - 1), 2(x - 1), 2.5(x - 1), 3*(x - 1)}, {x, 0, 1}, ImageSize -> 750, PlotStyle -> {{Blue, Thick, Dashing[None]}, {Red, Dashing[None]}, {Black, Dashing[None]}, {Black, Dashing[None]}, {Black, Dashing[None]}, {Black, Dashing[None]}}, Frame -> {{True, False}, {False, True}}, FrameLabel -> {{"y", None}, {None, "Fraction susceptible"}}, FrameTicks -> All, AxesOrigin -> {0, -4}]}{SIR without vital dynamics picture} \includegraphics{SIR without vital dynamics picture.pdf} \caption{Plot of $f(x,y)=\sin(x)\cos(y)$} \centering \end{figure}

\end{document}

EDIT:

Is this the woflramScript?

enter image description here

Errors:

enter image description here

Using the PDF method(I stretched the image), I have the following:

enter image description here

Math
  • 765
  • 2
    You might want to take a look at https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics. – campa Jun 14 '21 at 11:10
  • 2
    You can considerate to use also this specific package for Wolfram Language : latexalpha2. I add the link: https://ctan.math.illinois.edu/macros/latex/contrib/latexalpha2/latexalpha2.pdf. – Sebastiano Jun 14 '21 at 11:16
  • 1
    @Sebastiano : I get this error when trying to use the package you mention: "! Package latexalpha2 Error: Shell escape is not enabled, which is required to use latexalpha2." – Math Jun 14 '21 at 11:22
  • 1
    @Math The reason can be anything: if you have installed the package, what is the your LaTeX distribuition, etc. Please, can you add your minimal working example with more informations? Thank you very much. – Sebastiano Jun 14 '21 at 11:27
  • 1
    @Sebastiano Added – Math Jun 14 '21 at 11:30
  • 1
    @Sebastiano I am also using "quick build" so I don't know if this causes issues, I tried using PDFLaTex but same issues. Also I haven't called my file "pdflatex -shell-escape filename.tex" – Math Jun 14 '21 at 11:32
  • 1
    @Math In the meanwhile there are many packages that can you omit. I not can reproduce the problem :-(....however..+1 for your efforts. Thank you. – Sebastiano Jun 14 '21 at 11:34
  • 1
    @Sebastiano Thank you :) – Math Jun 14 '21 at 11:39
  • Thank you for your feedback! – Simon Dispa Jun 15 '21 at 14:34
  • @SimonDispa I tried the pdf method, the image doesn't look good, you can barely see the axis labels! maybe I need you use your method again! – Math Jun 16 '21 at 12:12
  • See the update to configure the tex editor. It looks you are using Texmaker – Simon Dispa Jun 16 '21 at 13:21
  • @SimonDispa I think I have it figured out now using a different method :) thank you for your input Sir! – Math Jun 16 '21 at 13:25
  • Thank you for your feedback! – Simon Dispa Jun 16 '21 at 13:27

1 Answers1

4

Use latexalpha2wlua.sty from latexalpha ported to windows

(1) Wolfram Engine must be installed and wolframscript must be fully working on the command prompt! (free version). WolframScript (for the Command Line)

Try wolframscript -version. You should get WolframScript 1.5.0 for Windows-x86-64 or similar.

(2) The file latexalpha2wlua.sty should be in the same directory of the .tex document.

(3) latexalpha2wlua loads all the necessary packages for this graph.

a

\documentclass[12pt, a4paper]{report}

\usepackage{latexalpha2wlua}

\begin{document}

\wolframgraphics{Plot[{Log[ x], 1(x - 1), 1.5(x - 1), 2(x - 1), 2.5(x - 1), 3*(x - 1)}, {x, 0, 1}, ImageSize -> 750, PlotStyle -> {{Blue, Thick, Dashing[None]}, {Red, Dashing[None]}, {Black, Dashing[None]}, {Black, Dashing[None]}, {Black, Dashing[None]}, {Black, Dashing[None]}}, Frame -> {{True, False}, {False, True}}, FrameLabel -> {{"y", None}, {None, "Fraction susceptible"}}, FrameTicks -> All, AxesOrigin -> {0, -4}]}{SIR.pdf}

\begin{figure} \centering \includegraphics[scale=.7]{SIR.pdf} \caption{Plot of $f(x,y)=\sin(x)\cos(y)$} \centering \end{figure}

\end{document}

UPDATE

Configure your tex editor:

pdflatex: => pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape %.tex

or

lualatex: => lualatex.exe -synctex=1 -interaction=nonstopmode -shell-escape %.tex

TeXstudio: Options > Configure TexStudio

ts

Then > Build & View or F5

ts2

Texmaker: Options > Configure Texmaker

tm

Then > Run

TM2

Simon Dispa
  • 39,141
  • I'm a amateur in computing so I'm a bit lost :( What am I supposed to do? – Math Jun 14 '21 at 14:45
  • @Math If you handle Mathematica, you are way ahead!

    Download and install the free version of wolframscript. It will install the Wolfram Engine on your machine at the same time.

    You will be asked to register and will receive a free license.

    Open the windows command (cmd.exe) and at the command prompt (like c:> in Windows) type wolframscript -version to test that the installation is ok and activated. It takes several seconds to answer the first time. Follow up to step 2.

    – Simon Dispa Jun 14 '21 at 15:12
  • for some reason its blocked on my university PC. I will try get it sorted out soon then message back! thank you for your answer by the way :) – Math Jun 14 '21 at 15:22
  • @Math If you are using the Mathematica license of the uni ask how to run wolframscript from the PC. – Simon Dispa Jun 14 '21 at 15:26
  • I will ask., thank you! – Math Jun 15 '21 at 11:01
  • Is this the script? I will attach a photo in the question. – Math Jun 15 '21 at 11:52
  • @Math This is the full Mathematica! (The script runs on the command prompt. ). Your simplest way is to generate the graph, export as a pdf and then use it in a LaTeX document: from \begin{figure} to \end{figure} only. Add only \usepackage{graphicx}. latexalpha2wlua is not longer needed – Simon Dispa Jun 15 '21 at 12:51
  • I did get the "WolframScript 1.6.0 for Windows-x86-64" on the command prompt. I saved the "latexalpha2wlua" file(as a mathematica notebook file(?)) in the same folder as the latex file. what shall I do next? – Math Jun 15 '21 at 12:53
  • @Math Run my code as any other LaTeX document. – Simon Dispa Jun 15 '21 at 12:56
  • I'm getting a lot of errors when running it as "quick build" with "view pdf" I'll show in the question – Math Jun 15 '21 at 13:03
  • @Math Try only my code. Your looks much more elaborate and might be conflicts between packages. As I said before: generate only the figure, with the full Mathematica or with my code and then import the result in your document. It does not make sense to recalculate the graph every time. – Simon Dispa Jun 15 '21 at 13:14
  • running only your latexalpha2wlua codes gives the errors shown in the question – Math Jun 15 '21 at 13:20
  • @Math It runs fine with windows 7 and 10 in a local PC. On what operating system are you running? In your local machine or in the cloud? – Simon Dispa Jun 15 '21 at 13:24
  • I'm using windows 10. its a university PC so I assume a local PC. the latexalpha2wlua filed should be saved as just "latexalpha2wlua" which will generate all the other files(.tex, .sty etc) correct? well actually since I have errors, its not generating the rest.. – Math Jun 15 '21 at 13:30
  • @Math It should be named latexalpha2wlua.sty NOT .tex! – Simon Dispa Jun 15 '21 at 13:40
  • still getting errors! When we run the latexalpha2wlua, what should we see? – Math Jun 15 '21 at 13:58
  • @Math Leave only my code and the latexalpha2wlua.sty in a directory and try again. – Simon Dispa Jun 15 '21 at 14:08
  • what shall i run the file as? "quick build" with "view pdf"? or..? – Math Jun 15 '21 at 14:15
  • @Math like any other tex file you compile – Simon Dispa Jun 15 '21 at 14:17
  • "could not start command. pdflatex - synctex=1 - interaction = nonstopmode %.tex" – Math Jun 15 '21 at 14:23
  • I give up hahaha, is there any other method? – Math Jun 15 '21 at 14:23
  • @Math (1) Use the full Mathematica you already have access to generate the figure as a pdf and then use it in the LaTeX document. (2) Ask some local TeX expert. The solution I posted was tested by many others. – Simon Dispa Jun 15 '21 at 14:27
  • Will do. Thanks for helping though, appreciate it :) – Math Jun 15 '21 at 14:32