尽管 wolframscript 在 Windows 10 的命令提示符下完全正常运行,但该软件包latexalpha2
给出了此错误
包 latexalpha2 错误:找不到使用 latexalpha2 所需的 WolframScript。
受到以下评论的启发这个相关问题,该软件包可能仅设计用于 Linux 设备。
因此,我希望有人能找到以下包文件所需的编辑,以使其lualatex
在 Windows 10 上运行。
%% This is file `latexalpha2.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% latexalpha2.dtx (with options: `package')
%%
%% This is a generated file.
%%
%% Copyright (C) 2019 by Yi Liu <[email protected]>
%%
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version. The latest version of this
%% license is in:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latexalpha2}
[2019/03/05 v1.1 latexalpha2]
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\RequirePackage{etoolbox}
\RequirePackage{pdftexcmds}
\RequirePackage{morewrites}
\RequirePackage{ifxetex}
\newbool{ifcache}
\newbool{ifmathics}
\DeclareOption{local}{\def\la@platform{-local}}
\DeclareOption{cloud}{\def\la@platform{-cloud}}
\DeclareOption{cache}{\booltrue{ifcache}}
\DeclareOption{nocache}{\boolfalse{ifcache}}
\DeclareOption{mathics}{\booltrue{ifmathics}}
\ExecuteOptions{local,cache}
\ProcessOptions\relax
\begingroup
\makeatletter
\catcode`#=12
\catcode`&=12
\gdef\@hashchar{#}
\gdef\@ampchar{&}
\gdef\backslash{\@backslashchar}
\gdef\hash{\@hashchar}
\makeatother
\endgroup
\def\la@codetempfile{latexalpha2_code.tmp}
\def\la@resulttempfile{}
\def\la@currcodehash{}
\newcommand{\la@cleancodetempfile}{\immediate\write18{rm -f \la@codetempfile}}
\newcommand{\la@unknownoption}[2]{\PackageError{latexalpha2}{Unknown option '#2' for \@backslashchar #1}{}}
\newcommand{\la@executewolfram}[1]{%
\IfFileExists{\la@resulttempfile}{%
\ifbool{ifcache}{\message{found cached output file \la@resulttempfile^^J}}{\la@executewolframcore{#1}}%
}{\la@executewolframcore{#1}}%
}
\newcommand{\la@executewolframcore}[1]{%
\notbool{ifmathics}{%
\def\la@wolframscript{wolframscript -file \la@codetempfile\space -print \ifblank{#1}{}{-format #1} \la@platform\space> \la@resulttempfile}%
}{%
\def\la@wolframscript{mathics \la@codetempfile\space> \la@resulttempfile}%
}%
\message{command: \la@wolframscript^^J}%
\immediate\write18{\la@wolframscript}%
}
\newcommand{\la@writecodefile}[2]{%
\message{------------ latexalpha2 -------------^^J}%
\message{\notbool{ifmathics}{wolfram}{mathics} code: #1^^J}%
\ifblank{#2}{}{\message{option: #2}}%
\gdef\la@currcodehash{\ifxetex\mdfivesum{#1#2}\else\pdfmdfivesum{#1#2}\fi}%
\gdef\la@resulttempfile{.latexalpha2_\[email protected]}%
\newwrite\tempfile%
\immediate\openout\tempfile=\la@codetempfile%
\immediate\write\tempfile{#1}%
\immediate\closeout\tempfile%
}
\newcommand{\la@notformathics}[1]{%
\ifbool{ifmathics}{\PackageError{latexalpha2}{\@backslashchar #1 is not available for the Mathics mode}{}}{}%
}
\def\la@texformat{tex}
\def\la@textformat{text}
\def\la@wolframformat{wolfram}
\def\la@wolframtwoformat{wolfram2}
\def\la@pdfformat{pdf}
\def\la@pngformat{png}
\def\la@jpgformat{jpg}
\newcommand{\wolfram}[2][tex]{%
\def\la@currformat{#1}%
\la@cleancodetempfile%
\notbool{ifmathics}{%
\la@writecodefile{#2}{#1}%
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\ifx \la@currformat \la@textformat \la@executewolfram{Text} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\la@unknownoption{wolfram}{#1}
\fi\fi\fi
}{%
\ifx \la@currformat \la@texformat \la@writecodefile{Print[TeXForm[#2]]}{#1} \else
\ifx \la@currformat \la@wolframformat \la@writecodefile{Print[#2]}{#1} \else
\la@unknownoption{wolfram}{#1}
\fi\fi
\la@executewolfram{}
}
\input{\la@resulttempfile}%%
\la@cleancodetempfile%
}
\newcommand{\wolframalpha}[2][tex]{%
\la@notformathics{wolframalpha}%
\def\la@currformat{#1}%
\la@cleancodetempfile%
\la@writecodefile{WolframAlpha["#2","%
\ifx\la@currformat\la@textformat ShortAnswer\else
\ifx\la@currformat\la@wolframtwoformat Result\else
WolframResult\fi\fi
"]}{#1}%
\ifx \la@currformat \la@textformat \la@executewolfram{} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\ifx \la@currformat \la@wolframtwoformat \la@executewolfram{} \else
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\la@unknownoption{wolframalpha}{#1}
\fi\fi\fi\fi
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframgraphics}[3][pdf]{%
\def\la@currformat{#1}%
\la@cleancodetempfile%
\notbool{ifmathics}{%
\la@writecodefile{#2}{#1}%
\ifx \la@currformat \la@pdfformat \la@executewolfram{PDF} \else
\ifx \la@currformat \la@pngformat \la@executewolfram{PNG} \else
\ifx \la@currformat \la@jpgformat \la@executewolfram{JPEG} \else
\la@unknownoption{wolframgraphics}{#1}
\fi\fi\fi
\ifx \la@currformat \la@pdfformat \immediate\write18{cp\space\la@resulttempfile\space#3.pdf} \else
\ifx \la@currformat \la@pngformat \immediate\write18{cp\space\la@resulttempfile\space#3.png} \else
\ifx \la@currformat \la@jpgformat \immediate\write18{cp\space\la@resulttempfile\space#3.jpg} \else
\la@unknownoption{wolframgraphics}{#1}
\fi\fi\fi
}{%
\la@writecodefile{Print[TeXForm[#2]]}{asy}
\la@executewolfram{}
\immediate\write18{cp\space\la@resulttempfile\space#3.asy}
}
}
\newcommand{\wolframsolve}[2]{%
\la@cleancodetempfile%
\def\la@solvecode{"\@backslashchar\@backslashchar begin{flalign*}"<>StringJoin@@("\@ampchar"<>ToString[ToExpression["TeXForm"][#2]]<>"="<>ToString[ToExpression["TeXForm"][\@hashchar]]<>"\@backslashchar\@backslashchar\@backslashchar\@backslashchar"\@ampchar/@(#2/.Solve[#1, #2]))<>"\@backslashchar\@backslashchar end{flalign*}"}
\notbool{ifmathics}{%
\la@writecodefile{\la@solvecode}{}%
\la@executewolfram{Text}%
}{%
\la@writecodefile{Print[\la@solvecode]}{}%
\la@executewolfram{}%
}
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframdsolve}[3]{%
\la@cleancodetempfile%
\def\la@solvecode{"\@backslashchar\@backslashchar begin{flalign*}"<>StringJoin@@("\@ampchar"<>ToString[ToExpression["TeXForm"][#2]]<>"="<>ToString[ToExpression["TeXForm"][\@hashchar]]<>"\@backslashchar\@backslashchar\@backslashchar\@backslashchar"\@ampchar/@(#2/.DSolve[#1, #2, #3]))<>"\@backslashchar\@backslashchar end{flalign*}"}
\notbool{ifmathics}{%
\la@writecodefile{\la@solvecode}{}%
\la@executewolfram{Text}%
}{%
\la@writecodefile{Print[\la@solvecode]}{}%
\la@executewolfram{}%
}
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframtex}[2][tex]{%
\la@notformathics{wolframtex}%
\def\la@currformat{#1}%
\la@cleancodetempfile%
\la@writecodefile{ToExpression["\unexpanded{#2}", TeXForm]}{#1}%
\immediate\write18{sed -i '' 's/\@backslashchar\@backslashchar/\@backslashchar\@backslashchar\@backslashchar\@backslashchar/g' \la@codetempfile}%
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\ifx \la@currformat \la@textformat \la@executewolfram{Text} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\la@unknownoption{wolframtex}{#1}
\fi\fi\fi
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframanimation}[2]{%
\la@notformathics{wolframanimation}%
\la@cleancodetempfile%
\la@writecodefile{#1}{}%
\la@executewolfram{GIF}
\immediate\write18{cp\space\la@resulttempfile\space#2.gif}%
\immediate\write18{mkdir -p #2}%
\immediate\write18{convert -coalesce #2.gif #2/frame.png}%
\la@cleancodetempfile%
}
\newcommand{\wolframtable}[1]{%
\la@notformathics{wolframtable}%
\la@cleancodetempfile%
\def\la@tablecode{StringJoin@@((StringRiffle[("$"<>Slot[1]<>"$")\@ampchar/@ToString/@TeXForm/@(Slot[1]),"\space\@ampchar\space"]<>"\@backslashchar\@backslashchar\@backslashchar\@backslashchar")\@ampchar/@(#1))}%
\la@writecodefile{\la@tablecode}{}%
\la@executewolfram{Text}%
\la@cleancodetempfile%
\input{\la@resulttempfile}%
}
\AtBeginDocument{%
%^^A check if shell-escape is available
\ifcase\pdf@shellescape
\PackageError{latexalpha2}{Shell escape is not enabled, which is required to use latexalpha2}{}\or
\PackageInfo{latexalpha2}{Shell escape is successfully enabled}{}\or
\PackageError{latexalpha2}{Shell escape is not enabled, which is required to use latexalpha2}{}\fi
%^^A check if wolframscript or mathics is available
\immediate\write18{command -v \notbool{ifmathics}{wolframscript}{mathics}; echo $? > latexalpha2_check.tmp}%
\newread\wsreturncodefile%
\immediate\openin\wsreturncodefile=latexalpha2_check.tmp%
\readline\wsreturncodefile to \wsreturncode%
\immediate\closein\wsreturncodefile%
%^^A https://tex.stackexchange.com/a/26873
\def\instring#1#2{TT\fi\begingroup\edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}%
\notbool{ifmathics}{%
\if\instring{0}{\wsreturncode}
\PackageInfo{latexalpha2}{WolframScript is available}{}\else
\PackageError{latexalpha2}{WolframScript cannot be found, which is required to use latexalpha2}{}\fi
}{%
\if\instring{0}{\wsreturncode}
\PackageInfo{latexalpha2}{Mathics is available}{}\else
\PackageError{latexalpha2}{Mathics cannot be found, which is required to use the Mathics mode of latexalpha2}{}\fi
}
}
\AtEndDocument{%
\ifbool{ifcache}{}{\immediate\write18{rm -f .latexalpha2_*.out}}
}
\endinput
%%
%% End of file `latexalpha2.sty'.
答案1
更新答案
对已发布的问题的回答:适用latexalpha2
于 Windows 和lualatex
/ pdflatex
。
此代码测试了原始包的大部分功能。
\documentclass[12pt,a4paper]{article}
\RequirePackage{float}%
\RequirePackage[cache]{latexalpha2wlua} % option cache (faster the second run) or nocache (recalculate always)
\begin{document}
\begin{figure}[H]
\wolframgraphics{Plot3D[Sin[x]Cos[y],{x,-2Pi,2Pi},{y,-2Pi,2Pi}]}{Plot3Db}
\includegraphics{Plot3Db.pdf}
\caption{Plot 3D of $f(x,y)=\sin(x)\cos(y)$}
\centering
\end{figure}
Laplace Transform of $t^4 sin(t)$
$$ \wolfram{LaplaceTransform[t^4 Sin[t],t,s]} $$
Generates a power series expansion
$$ \wolfram{Series[Exp[x],{x,0,5}]} $$
\bigskip
Compton scattering for electron \bigskip
$\wolframalpha{Compton scattering for electron}$
\bigskip
Solve the equation $a x^2+b x+c=0$ and display the corresponding results
\wolframsolve{a x^2+b x+c==0}{x}
\newpage
\begin{table}[H]
\centering
\begin{tabular}{cccc} %set the correct number of columns!
\toprule
\wolframtable{Join[{{x,x^2,x^3,x^4}}, Table[{i,i^2,i^3,i^4},{i,6}]]}
\end{tabular}
\caption{Generate a table $x$, $x^2$, $x^3$, $x^4$}
\end{table}
\bigskip
The population of Shanghai is $\wolframalpha{Shanghai population}$, which
is $\wolframalpha{ratio of Shanghai population and NYC population}$ times the
population of New York City.
\bigskip
Solve differential equations $y'(x) + y(x) = a *sin(x)*y(x)*x $
\wolframdsolve{y'[x]+y[x]==a Sin[x]}{y[x]}{x}
\end{document}
我重命名的包latexalpha2wlua
可以与 Windows 和 一起使用lualatex
。
%%
%% This is file `latexalpha2wlua.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% latexalpha2.dtx (with options: `package')
%%
%% This is a generated file.
%%
%% Copyright (C) 2019 by Yi Liu <[email protected]>
%%
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version. The latest version of this
%% license is in:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%%
%% modified for windows and luatex by Simon Dispa (2021) v1.0e
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latexalpha2wlua}[2021/01/21 v1.0d latexalpha2wlua]
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\RequirePackage{etoolbox}
\RequirePackage{pdftexcmds}
\RequirePackage{shellesc}
\RequirePackage{booktabs}%
\RequirePackage{animate}
\newbool{ifcache}
\DeclareOption{local}{\def\la@platform{-local}}
\DeclareOption{cloud}{\def\la@platform{-cloud}}
\DeclareOption{cache}{\booltrue{ifcache}}
\DeclareOption{nocache}{\boolfalse{ifcache}}
\ExecuteOptions{local}
\ProcessOptions\relax
\begingroup
\makeatletter
\catcode`#=12
\catcode`&=12
\gdef\@hashchar{#}
\gdef\@ampchar{&}
\gdef\backslash{\@backslashchar}
\makeatother
\endgroup
\def\la@codetempfile{la2w_code.wls}
\def\la@resulttempfile{}
\def\la@currcodehash{}
\def\la@animaoutdir{}
\def\la@outdir{la_output}
\def\la@midrule{midrule}
\newcommand{\la@unknownoption}[2]{\PackageError{latexalpha2wlua}{Unknown option '#2' for \@backslashchar #1}{}}
\newcommand{\la@makedir}[1]{IF NOT EXIST #1 md #1}
\newcommand{\la@deldir}[1]{rd /Q /S #1 }
\newcommand{\la@executewolfram}[1]{%
\IfFileExists{\la@resulttempfile}{\ifbool{ifcache}{}{\la@executewolframcore{#1}}
}{\la@executewolframcore{#1}}
}
\newcommand{\la@executewolframcore}[1]{%
\def\la@wolframscript{wolframscript -file \la@outdir\backslash\la@codetempfile\space -print -format #1 \la@platform\space> \la@resulttempfile}%
\immediate\write18{\la@wolframscript}%
}
\newcommand{\la@writecodefile}[2]{%
\gdef\la@currcodehash{\pdf@mdfivesum{#1#2}}%%<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\gdef\la@resulttempfile{\la@outdir\backslash#2_\[email protected]}%
\newwrite\tempfile%
\immediate\openout\tempfile=\la@outdir\backslash\la@codetempfile%
\immediate\write\tempfile{#1}%
\immediate\closeout\tempfile%
}
\def\la@texformat{tex}
\def\la@textformat{txt}
\def\la@wolframformat{wolfram}
\def\la@wolframtwoformat{wolfram2}
\def\la@pdfformat{pdf}
\def\la@pngformat{png}
\def\la@jpgformat{jpg}
\newcommand{\wolfram}[2][tex]{%
\message{>>>> starting wolfram (#1): please wait ... ^^J}%
\def\la@currformat{#1}%
\la@writecodefile{#2}{#1}%
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\ifx \la@currformat \la@textformat \la@executewolfram{txt} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\la@unknownoption{wolfram}{#1}
\fi\fi\fi
\input{\la@resulttempfile}%
}
\newcommand{\wolframalpha}[2][tex]{%
\message{>>>> starting wolframalpha (-> #1): please wait ... ^^J}%
\def\la@currformat{#1}%
\la@writecodefile{WolframAlpha["#2","%
\ifx\la@currformat\la@textformat ShortAnswer\else
\ifx\la@currformat\la@wolframtwoformat Result\else
WolframResult\fi\fi
"]}{#1}%
\ifx \la@currformat \la@textformat \la@executewolfram{} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\ifx \la@currformat \la@wolframtwoformat \la@executewolfram{} \else
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\la@unknownoption{wolframalpha}{#1}
\fi\fi\fi\fi
\input{\la@resulttempfile}%
}
\newcommand{\wolframgraphics}[3][pdf]{%
\message{>>>> starting wolfram #1 graphics: please wait ... ^^J}%
\def\la@currformat{#1}%
\la@writecodefile{#2}{#1}%
\ifx \la@currformat \la@pdfformat \la@executewolfram{PDF} \else
\ifx \la@currformat \la@pngformat \la@executewolfram{PNG} \else
\ifx \la@currformat \la@jpgformat \la@executewolfram{JPEG} \else
\la@unknownoption{wolframgraphics}{#1}
\fi\fi\fi
\ifx \la@currformat \la@pdfformat \immediate\write18{copy\space\la@resulttempfile\space#3.pdf >NUL} \else
\ifx \la@currformat \la@pngformat \immediate\write18{copy\space\la@resulttempfile\space#3.png >NUL} \else
\ifx \la@currformat \la@jpgformat \immediate\write18{copy\space\la@resulttempfile\space#3.jpg >NUL} \else
\la@unknownoption{wolframgraphics}{#1}
\fi\fi\fi
}
\newcommand{\wolframsolve}[2]{%
\def\la@currformat{#2}%
\message{>>>> starting wolfram (-> tex) solve: please wait ... ^^J}%
\la@writecodefile{"\@backslashchar\@backslashchar begin{flalign*}"<>StringJoin@@("\@ampchar"<>ToString[ToExpression["TeXForm"][#2]]<>"="<>ToString[ToExpression["TeXForm"][\@hashchar]]<>"\@backslashchar\@backslashchar\@backslashchar\@backslashchar"\@ampchar/@(#2/.Solve[#1, #2]))<>"\@backslashchar\@backslashchar end{flalign*}"}{}%
\la@executewolfram{txt}%
\input{\la@resulttempfile}%
}
\newcommand{\wolframdsolve}[3]{%
\message{>>>> starting wolfram (-> tex) diff. eq. solve: please wait ... ^^J}%
\la@writecodefile{"\@backslashchar\@backslashchar begin{flalign*}"<>StringJoin@@("\@ampchar"<>ToString[ToExpression["TeXForm"][#2]]<>"="<>ToString[ToExpression["TeXForm"][\@hashchar]]<>"\@backslashchar\@backslashchar\@backslashchar\@backslashchar"\@ampchar/@(#2/.DSolve[#1, #2, #3]))<>"\@backslashchar\@backslashchar end{flalign*}"}{}%
\la@executewolfram{txt}%
\input{\la@resulttempfile}%
}
\newcommand{\wolframtable}[1]{%
\message{>>>> starting wolfram table: please wait ... ^^J}%
\def\la@tablecode{StringJoin@@(%
(StringRiffle[("$"<>Slot[1]<>"$") \@ampchar/@ToString/@TeXForm/@(Slot[1]),"\space\@ampchar\space" ]
<> "\space\@backslashchar\@backslashchar\@backslashchar\@backslashchar\space\@backslashchar\@backslashchar\la@midrule\space")
\@ampchar/@(#1)
)}%
\la@writecodefile{\la@tablecode}{tex}%
\la@executewolfram{Text}%
\input{\la@resulttempfile}%
}
\newcommand{\wolframonlygif}[2]{%
\message{>>>> starting wolfram only gif: please wait wait wait ... ^^J}%
\la@writecodefile{#1}{gif}%
\la@executewolfram{GIF}
\immediate\write18{copy\space\la@resulttempfile\space #2.gif >NUL}%
}
\newcommand{\wolframanimation}[2]{%
\message{>>>> starting wolfram animation: please wait wait wait ... ^^J}%
\gdef\la@animaoutdir{#2}
\immediate\write18{\la@makedir{\la@animaoutdir}}
\la@writecodefile{#1}{gif}%
\la@executewolfram{GIF}
\immediate\write18{copy\space\la@resulttempfile\space\la@animaoutdir\backslash#2.gif >NUL}% OK
\immediate\write18{convert -coalesce \space\la@animaoutdir\backslash#2.gif #2/frame.png}%
}
\AtBeginDocument{%
\immediate\write18{\la@makedir{\la@outdir}}
%% Check if wolframscript is available
\immediate\write18{wolframscript -code 2+2 > la2_check.tmp}%
\newread\wsreturncodefile%
\immediate\openin\wsreturncodefile= la2_check.tmp%
\readline\wsreturncodefile to \wsreturncode%
\immediate\closein\wsreturncodefile%
% %^^A https://tex.stackexchange.com/a/26873
\def\instring#1#2{TT\fi\begingroup\edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}%
\if\instring{4}{\wsreturncode}
\immediate\write18{del /Q la2_check.tmp >NUL}
\PackageInfo{latexalpha2wlua}{WolframScript is available}{}\else
\PackageError{latexalpha2wlua}{WolframScript cannot be found. Required to use latexalpha2wlua}{}
\fi
}
\AtEndDocument{%
\ifbool{ifcache}{}{\immediate\write18{\la@deldir{\la@outdir}}}
}
\endinput
%%
%% End of file `latexalpha2wlua.sty'.
笔记
(0)必须安装 Wolfram Engine,并且 wolframscript 必须在命令提示符下完全运行!示例可以在
https://reference.wolfram.com/language/ref/program/wolframscript.html
(1)在 Windows 7 上测试。
(2)该文件latexalpha2wlua.sty
应与文档位于同一目录下.tex
。
(3)使用 lualatex 和 pdflatex 测试。请参阅 MWE
(4) 简化代码,消除无害消息。
(5)cache
如果查询不变,使用该选项可使重新编译速度更快。目前,所有输出文件仍保留在同一目录中。该选项nocache
会清除所有内容,但第二次会重新计算所有内容。
(6)要使用相同的包制作动画 GIF,请参阅
答案2
这是我对 Simon Dispa 的伟大作品的看法原始答案。
%% This is file `latexalpha2Win.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% latexalpha2.dtx (with options: `package')
%%
%% This is a generated file.
%%
%% Copyright (C) 2019 by Yi Liu <[email protected]>
%%
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version. The latest version of this
%% license is in:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%% modified for windows and luatex by Simon Dispa (2021)
%% https://tex.stackexchange.com/a/579254/2288
%% and Diaa
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latexalpha2Win}
[2021/01/19 v1.0 latexalpha2Win]
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\RequirePackage{etoolbox}
\RequirePackage{pdftexcmds}
\RequirePackage{shellesc}
\newbool{ifcache}
\DeclareOption{local}{\def\la@platform{-local}}
\DeclareOption{cloud}{\def\la@platform{-cloud}}
\DeclareOption{cache}{\booltrue{ifcache}}
\DeclareOption{nocache}{\boolfalse{ifcache}}
\ExecuteOptions{local,cache}
\ProcessOptions\relax
\begingroup
\makeatletter
\catcode`#=12
\catcode`&=12
\gdef\@hashchar{#}
\gdef\@ampchar{&}
\gdef\backslash{\@backslashchar}
\makeatother
\endgroup
\def\la@codetempfile{latexalpha2_code.tmp}
\def\la@resulttempfile{}
\def\la@currcodehash{}
\newcommand{\la@cleancodetempfile}{\immediate\write18{del /F \la@codetempfile}}
\newcommand{\la@unknownoption}[2]{\PackageError{latexalpha2}{Unknown option '#2' for #1}{}}
\newcommand{\la@executewolfram}[1]{%
\IfFileExists{\la@resulttempfile}{
\ifbool{ifcache}{\message{found cached output file \la@resulttempfile^^J}}{\la@executewolframcore{#1}}
}{\la@executewolframcore{#1}}
}
\newcommand{\la@executewolframcore}[1]{%
\def\la@wolframscript{wolframscript -file \la@codetempfile\space -print \ifblank{#1}{}{-format #1} \la@platform\space> \la@resulttempfile}%
\message{command: \la@wolframscript^^J}%
\immediate\write18{\la@wolframscript}%
}
\newcommand{\la@writecodefile}[2]{%
\message{------------ latexalpha2 x-------------^^J}%
\message{wolfram code: #1^^J}%
\ifblank{#2}{}{\message{option: #2}}%
\gdef\la@currcodehash{\pdf@mdfivesum{#1#2}}%
\gdef\la@resulttempfile{.latexalpha2_\[email protected]}%
\newwrite\tempfile%
\immediate\openout\tempfile=\la@codetempfile%
\immediate\write\tempfile{#1}%
\immediate\closeout\tempfile%
}
\def\la@texformat{tex}
\def\la@textformat{text}
\def\la@wolframformat{wolfram}
\def\la@wolframtwoformat{wolfram2}
\def\la@pdfformat{pdf}
\def\la@pngformat{png}
\def\la@jpgformat{jpg}
\newcommand{\wolfram}[2][tex]{%
\def\la@currformat{#1}%
\la@writecodefile{#2}{#1}%
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\ifx \la@currformat \la@textformat \la@executewolfram{Text} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\la@unknownoption{wolfram}{#1}
\fi\fi\fi
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframalpha}[2][tex]{%
\def\la@currformat{#1}%
\la@writecodefile{WolframAlpha["#2","%
\ifx\la@currformat\la@textformat ShortAnswer\else
\ifx\la@currformat\la@wolframtwoformat Result\else
WolframResult\fi\fi
"]}{#1}%
\ifx \la@currformat \la@textformat \la@executewolfram{} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\ifx \la@currformat \la@wolframtwoformat \la@executewolfram{} \else
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\la@unknownoption{wolframalpha}{#1}
\fi\fi\fi\fi
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframgraphics}[3][pdf]{%
\def\la@currformat{#1}%
\la@writecodefile{#2}{#1}%
\ifx \la@currformat \la@pdfformat \la@executewolfram{PDF} \else
\ifx \la@currformat \la@pngformat \la@executewolfram{PNG} \else
\ifx \la@currformat \la@jpgformat \la@executewolfram{JPEG} \else
\la@unknownoption{wolframgraphics}{#1}
\fi\fi\fi
\ifx \la@currformat \la@pdfformat \immediate\write18{copy \la@resulttempfile #3.pdf} \else
\ifx \la@currformat \la@pngformat \immediate\write18{copy \la@resulttempfile #3.png} \else
\ifx \la@currformat \la@jpgformat \immediate\write18{copy \resulttempfile #3.jpg} \else
\la@unknownoption{wolframgraphics}{#1}
\fi\fi\fi
\la@cleancodetempfile
}
\newcommand{\wolframsolve}[2]{%
\la@writecodefile{"\@backslashchar\@backslashchar begin{flalign*}"<>StringJoin@@("\@ampchar"<>ToString[ToExpression["TeXForm"][#2]]<>"="<>ToString[ToExpression["TeXForm"][\@hashchar]]<>"\@backslashchar\@backslashchar\@backslashchar\@backslashchar"\@ampchar/@(#2/.Solve[#1, #2]))<>"\@backslashchar\@backslashchar end{flalign*}"}{}%
\la@executewolfram{Text}%
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframdsolve}[3]{%
\la@writecodefile{"\@backslashchar\@backslashchar begin{flalign*}"<>StringJoin@@("\@ampchar"<>ToString[ToExpression["TeXForm"][#2]]<>"="<>ToString[ToExpression["TeXForm"][\@hashchar]]<>"\@backslashchar\@backslashchar\@backslashchar\@backslashchar"\@ampchar/@(#2/.DSolve[#1, #2, #3]))<>"\@backslashchar\@backslashchar end{flalign*}"}{}%
\la@executewolfram{Text}%
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframtex}[2][tex]{%
\def\la@currformat{#1}%
\la@writecodefile{ToExpression["\unexpanded{#2}", TeXForm]}{#1}%
\immediate\write18{sed -i '' 's/\@backslashchar\@backslashchar/\@backslashchar\@backslashchar\@backslashchar\@backslashchar/g' \la@codetempfile}%
\ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
\ifx \la@currformat \la@textformat \la@executewolfram{Text} \else
\ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
\la@unknownoption{wolframtex}{#1}
\fi\fi\fi
\input{\la@resulttempfile}%
\la@cleancodetempfile%
}
\newcommand{\wolframanimation}[2]{%
\la@writecodefile{#1}{}%
\la@executewolfram{GIF}
\immediate\write18{copy \space\la@resulttempfile\space#2.gif}%
\immediate\write18{md #2}%
\immediate\write18{convert -coalesce #2.gif #2/frame.png}%
\la@cleancodetempfile%
}
\AtBeginDocument{%
% Check if shell-escape is available
\ifcase\pdf@shellescape
\PackageError{latexalpha2}{Shell escape is not enabled, which is required to use latexalpha2}{}\or
\PackageInfo{latexalpha2}{Shell escape is successfully enabled}{}\or
\PackageError{latexalpha2}{Shell escape is not enabled, which is required to use latexalpha2}{}\fi
% Check if wolframscript is available
\immediate\write18{where wolframscript >latexalpha2_check.tmp 2>nul}%
% https://stackoverflow.com/a/35408403/2849383
%\immediate\write18{where /q wolframscript \ampchar echo \@percentchar ERRORLEVEL\@percentchar > latexalpha2_check.tmp}%
% https://superuser.com/a/1618520/452161
% https://superuser.com/a/718194/452161
% https://stackoverflow.com/a/25696405/2849383
\newread\wsreturncodefile%
\immediate\openin\wsreturncodefile=latexalpha2_check.tmp%
\readline\wsreturncodefile to \wsreturncode%
\immediate\closein\wsreturncodefile%
% https://tex.stackexchange.com/a/26873
\def\instring#1#2{TT\fi\begingroup\edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}%
\if\instring{{wolframscript.exe}}{\wsreturncode}
\PackageInfo{latexalpha2}{WolframScript is available}{}
\immediate\write18{del /F latexalpha2_check.tmp}\else
\immediate\write18{del /F latexalpha2_check.tmp}
\PackageError{latexalpha2}{WolframScript cannot be found, which is required to use latexalpha2}{}
\fi
}
\AtEndDocument{%
\ifbool{ifcache}{\immediate\write18{del/Q *.out}}{ }
}
\endinput
%%
%% End of file `latexalpha2Win.sty'.