Advertisement
diaaa

Untitled

Jan 17th, 2021
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.92 KB | None | 0 0
  1. %% This is file `latexalpha2wlua.sty',
  2. %% generated with the docstrip utility.
  3. %%
  4. %% The original source files were:
  5. %%
  6. %% latexalpha2.dtx (with options: `package')
  7. %%
  8. %% This is a generated file.
  9. %%
  10. %% Copyright (C) 2019 by Yi Liu <me@yliu.io>
  11. %%
  12. %% This file may be distributed and/or modified under the conditions of
  13. %% the LaTeX Project Public License, either version 1.3c of this license
  14. %% or (at your option) any later version. The latest version of this
  15. %% license is in:
  16. %%
  17. %% http://www.latex-project.org/lppl.txt
  18. %%
  19. %% and version 1.3c or later is part of all distributions of LaTeX
  20. %% version 2006/05/20 or later.
  21. %% modified for windows sidispa@gmail.com 2021
  22. %%
  23. \NeedsTeXFormat{LaTeX2e}
  24. \ProvidesPackage{latexalpha2wlua}%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  25. [2019/03/02 v1.0 latexalpha2]
  26. \RequirePackage{graphicx}
  27. \RequirePackage{amsmath}
  28. \RequirePackage{etoolbox}
  29. \RequirePackage{pdftexcmds}
  30. \RequirePackage{shellesc}%<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  31. %\RequirePackage{newverbs}
  32. %\Verbdef\myamp{&} % https://tex.stackexchange.com/a/17464/2288
  33.  
  34. \newbool{ifcache}
  35.  
  36. \DeclareOption{local}{\def\la@platform{-local}}
  37. \DeclareOption{cloud}{\def\la@platform{-cloud}}
  38. \DeclareOption{cache}{\booltrue{ifcache}}
  39. \DeclareOption{nocache}{\boolfalse{ifcache}}
  40.  
  41. \ExecuteOptions{local,cache}
  42. \ProcessOptions\relax
  43.  
  44. \begingroup
  45. \makeatletter
  46. \catcode`#=12
  47. \catcode`&=12
  48. \gdef\@hashchar{#}
  49. \gdef\@ampchar{&}
  50. \gdef\backslash{\@backslashchar}
  51. \makeatother
  52. \endgroup
  53.  
  54. \def\la@codetempfile{latexalpha2_code.tmp}
  55. \def\la@resulttempfile{}
  56. \def\la@currcodehash{}
  57. %%%powershell -command "dir \"c:\Program Files\" "
  58.  
  59. \newcommand{\la@cleancodetempfile}{\immediate\write18{del /F \la@codetempfile}}
  60. \newcommand{\la@unknownoption}[2]{\PackageError{latexalpha2}{Unknown option '#2' for #1}{}}
  61.  
  62. \newcommand{\la@executewolfram}[1]{%
  63. \IfFileExists{\la@resulttempfile}{
  64. \ifbool{ifcache}{\message{found cached output file \la@resulttempfile^^J}}{\la@executewolframcore{#1}}
  65. }{\la@executewolframcore{#1}}
  66. }
  67.  
  68. \newcommand{\la@executewolframcore}[1]{%
  69. \def\la@wolframscript{wolframscript -file \la@codetempfile\space -print \ifblank{#1}{}{-format #1} \la@platform\space> \la@resulttempfile}%
  70. \message{command: \la@wolframscript^^J}%
  71. \immediate\write18{\la@wolframscript}%
  72. }
  73.  
  74. \newcommand{\la@writecodefile}[2]{%
  75. \message{------------ latexalpha2 x-------------^^J}%
  76. \message{wolfram code: #1^^J}%
  77. \ifblank{#2}{}{\message{option: #2}}
  78. \gdef\la@currcodehash{\pdf@mdfivesum{#1#2}}%%<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  79. \gdef\la@resulttempfile{.latexalpha2_\la@currcodehash.out}%
  80. \newwrite\tempfile%
  81. \immediate\openout\tempfile=\la@codetempfile%
  82. \immediate\write\tempfile{#1}%
  83. \immediate\closeout\tempfile%
  84. }
  85.  
  86. \def\la@texformat{tex}
  87. \def\la@textformat{text}
  88. \def\la@wolframformat{wolfram}
  89. \def\la@wolframtwoformat{wolfram2}
  90. \def\la@pdfformat{pdf}
  91. \def\la@pngformat{png}
  92. \def\la@jpgformat{jpg}
  93.  
  94. \newcommand{\wolfram}[2][tex]{%
  95. \def\la@currformat{#1}%
  96. %\la@cleancodetempfile%
  97. \la@writecodefile{#2}{#1}%
  98. \ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
  99. \ifx \la@currformat \la@textformat \la@executewolfram{Text} \else
  100. \ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
  101. \la@unknownoption{wolfram}{#1}
  102. \fi\fi\fi
  103. \input{\la@resulttempfile}%
  104. \la@cleancodetempfile%
  105. }
  106.  
  107. \newcommand{\wolframalpha}[2][tex]{%
  108. \def\la@currformat{#1}%
  109. %\la@cleancodetempfile%
  110. \la@writecodefile{WolframAlpha["#2","%
  111. \ifx\la@currformat\la@textformat ShortAnswer\else
  112. \ifx\la@currformat\la@wolframtwoformat Result\else
  113. WolframResult\fi\fi
  114. "]}{#1}%
  115. \ifx \la@currformat \la@textformat \la@executewolfram{} \else
  116. \ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
  117. \ifx \la@currformat \la@wolframtwoformat \la@executewolfram{} \else
  118. \ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
  119. \la@unknownoption{wolframalpha}{#1}
  120. \fi\fi\fi\fi
  121. \input{\la@resulttempfile}%
  122. \la@cleancodetempfile%
  123. }
  124.  
  125. \newcommand{\wolframgraphics}[3][pdf]{%
  126. \def\la@currformat{#1}%
  127. \la@writecodefile{#2}{#1}%
  128. \ifx \la@currformat \la@pdfformat \la@executewolfram{PDF} \else
  129. \ifx \la@currformat \la@pngformat \la@executewolfram{PNG} \else
  130. \ifx \la@currformat \la@jpgformat \la@executewolfram{JPEG} \else
  131. \la@unknownoption{wolframgraphics}{#1}
  132. \fi\fi\fi
  133. \ifx \la@currformat \la@pdfformat \immediate\write18{copy\space\la@resulttempfile\space#3.pdf} \else %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  134. \ifx \la@currformat \la@pngformat \immediate\write18{copy\space\la@resulttempfile\space#3.png} \else %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  135. \ifx \la@currformat \la@jpgformat \immediate\write18{copy\space\resulttempfile\space#3.jpg} \else %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  136. \la@unknownoption{wolframgraphics}{#1}
  137. \fi\fi\fi
  138. \la@cleancodetempfile
  139. }
  140.  
  141. \newcommand{\wolframsolve}[2]{%
  142. \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*}"}{}%
  143. \la@executewolfram{Text}%
  144. \input{\la@resulttempfile}%
  145. \la@cleancodetempfile%
  146. }
  147.  
  148. \newcommand{\wolframdsolve}[3]{%
  149. \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*}"}{}%
  150. \la@executewolfram{Text}%
  151. \input{\la@resulttempfile}%
  152. \la@cleancodetempfile%
  153. }
  154.  
  155. \newcommand{\wolframtex}[2][tex]{%
  156. \def\la@currformat{#1}%
  157. \la@writecodefile{ToExpression["\unexpanded{#2}", TeXForm]}{#1}%
  158. \immediate\write18{sed -i '' 's/\@backslashchar\@backslashchar/\@backslashchar\@backslashchar\@backslashchar\@backslashchar/g' \la@codetempfile}%
  159. \ifx \la@currformat \la@texformat \la@executewolfram{TeXForm} \else
  160. \ifx \la@currformat \la@textformat \la@executewolfram{Text} \else
  161. \ifx \la@currformat \la@wolframformat \la@executewolfram{} \else
  162. \la@unknownoption{wolframtex}{#1}
  163. \fi\fi\fi
  164. \input{\la@resulttempfile}%
  165. \la@cleancodetempfile%
  166. }
  167.  
  168. \newcommand{\wolframanimation}[2]{%
  169. \la@writecodefile{#1}{}%
  170. \la@executewolfram{GIF}
  171. \immediate\write18{copy \space\la@resulttempfile\space#2.gif}% %<<<<<<<<<<<<<<<<
  172. \immediate\write18{md #2}%% %<<<<<<<<<<<<<<<<
  173. \immediate\write18{convert -coalesce #2.gif #2/frame.png}%
  174. \la@cleancodetempfile%
  175. }
  176.  
  177.  
  178. \AtBeginDocument{%
  179. %^^A heck if shell-escape is available
  180. \ifcase\pdf@shellescape
  181. \PackageError{latexalpha2}{Shell escape is not enabled, which is required to use latexalpha2}{}\or
  182. \PackageInfo{latexalpha2}{Shell escape is successfully enabled}{}\or
  183. \PackageError{latexalpha2}{Shell escape is not enabled, which is required to use latexalpha2}{}\fi
  184.  
  185. %^^A check if wolframscript is available
  186. \immediate\write18{wolframscript \@ampchar echo \@percentchar ERRORLEVEL\@percentchar > latexalpha2_check.tmp}%
  187. %\immediate\write18{command wolframscript; echo $? > latexalpha2_check.tmp}%
  188. \newread\wsreturncodefile%
  189. \immediate\openin\wsreturncodefile=latexalpha2_check.tmp%
  190. \readline\wsreturncodefile to \wsreturncode%
  191. \immediate\closein\wsreturncodefile%
  192. %^^A https://tex.stackexchange.com/a/26873
  193. \def\instring#1#2{TT\fi\begingroup\edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}%
  194. \if\instring{0}{\wsreturncode}
  195. \PackageInfo{latexalpha2}{WolframScript is available}{}\else
  196. %\PackageError{latexalpha2}{WolframScript cannot be found, which is required to use latexalpha2}{} %<<<<<<<<<<<<<<<<<
  197. \fi
  198. }
  199.  
  200. \AtEndDocument{%
  201. \ifbool{ifcache}{\immediate\write18{del/Q *.out}}{ }
  202. }
  203. \endinput
  204. %%
  205. %% End of file `latexalpha2.sty'.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement