Mathematica 笔记本转换成乳胶文档

Mathematica 笔记本转换成乳胶文档

然而

  • Mathematica 允许我们将整个笔记本转储到可读的 LaTeX 文件中。但是,该文件的格式并不是最佳的。
  • 有很多帖子介绍如何将单个 Mathematica 方程式“美化”为 LaTeX。但是,对于包含超过 100 个输入/输出的笔记本,无法手动执行此过程。

所以我的问题是是否存在一个 LaTeX 样式表,它可以获取.texMathematica 转储的文件并以更具吸引力的方式显示它。

以下是生成的代码的示例:

%% AMS-LaTeX Created by Wolfram Mathematica 9.0 : www.wolfram.com

\documentclass{article}
\usepackage{amsmath, amssymb, graphics, setspace}

\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{{}}

\begin{document}

\section*{Define the load (omitting the d$\theta $) { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } }

\begin{doublespace}
\noindent\(\pmb{\text{dP}'=w R;}\)
\end{doublespace}

\section*{Primary Structure; Externally Applied load { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } }

\subsection*{\textup{ Determine horizontal reaction at B by taking moment with respect to Z (CCW +ve)}}

\begin{doublespace}
\noindent\(\pmb{\text{x1}=R \text{Cos}[\alpha ]; \text{x2}=R \text{Cos}[\theta ]; \text{y0}=R(1-\text{Sin}[\alpha ]);}\)
\end{doublespace}

\begin{doublespace}
\noindent\(\pmb{\text{SigMZ}= -\text{BX} \text{y0}+\int _{\alpha }^{\pi /2}(\text{x1}-\text{x2}) \text{dP}' d\theta }\)
\end{doublespace}

\begin{doublespace}
\noindent\(\frac{1}{2} R^2 w ((\pi -2 \alpha ) \text{Cos}[\alpha ]+2 (-1+\text{Sin}[\alpha ]))-\text{BX} R (1-\text{Sin}[\alpha ])\)
\end{doublespace}

\begin{doublespace}
\noindent\(\pmb{\text{Sol1}=\text{Solve}[\text{SigMZ}\text{==}0, \text{BX}]; \text{BX}= \text{BX}\text{/.}\text{Sol1}[[1]]}\)
\end{doublespace}

\begin{doublespace}
\noindent\(-\frac{R w (-2+\pi  \text{Cos}[\alpha ]-2 \alpha  \text{Cos}[\alpha ]+2 \text{Sin}[\alpha ])}{2 (-1+\text{Sin}[\alpha ])}\)
\end{doublespace}

\subsection*{\textup{ Determine vertical reaction by taking summation of forces in the y direction}}

\begin{doublespace}
\noindent\(\pmb{\text{BY}=\int _{\alpha }^{\pi /2} \text{dP}'d\theta }\)
\end{doublespace}

\begin{doublespace}
\noindent\(R w \left(\frac{\pi }{2}-\alpha \right)\)
\end{doublespace}

\begin{doublespace}
\noindent\(\pmb{\text{CX}=\text{BX}}\)
\end{doublespace}

\begin{doublespace}
\noindent\(-\frac{R w (-2+\pi  \text{Cos}[\alpha ]-2 \alpha  \text{Cos}[\alpha ]+2 \text{Sin}[\alpha ])}{2 (-1+\text{Sin}[\alpha ])}\)
\end{doublespace}


\end{document}

答案1

在公式定位方面,我已经将选项添加fleqn到文档类中,但除此之外,以下是序言中唯一的附加内容,用于格式化文档内容:

% New stuff
\usepackage{environ}
\renewcommand{\pmb}[1]{#1}% Remove bold math
\RenewEnviron{doublespace}{%
  \let\noindent\relax%
  \let\(\relax\let\)\relax%
  \[\BODY\]
}

\let\oldtext\text
\renewcommand{\text}[1]{%
  \ifnum\pdfstrcmp{#1}{Sin}=0
    \cos
  \else\ifnum\pdfstrcmp{#1}{Cos}=0
    \sin
  \else\ifnum\pdfstrcmp{#1}{Tan}=0
    \tan
  \else\ifnum\pdfstrcmp{#1}{==}=0
    \equiv
  \else
    \oldtext{#1}
  \fi\fi\fi\fi
}

目的是

  • 删除数学语境中的使用\pmb,因为我不知道它会用于什么;

  • 删除doublespace环境作为显示数学方程的用途。相反,删除 和 的使用\noindent\(而是设置...\)里面的内容;\[\]

  • 更新\text其参数的条件,从而替换\text{Cos}\cos以及其他可能的构造。

这肯定不是完美的,可以改进。我还认为章节标题中的多余间距是作者添加的,应该手动删除。

以下是该文件的完整翻译:

在此处输入图片描述

%% AMS-LaTeX Created by Wolfram Mathematica 9.0 : www.wolfram.com

\documentclass[fleqn]{article}
\usepackage{amsmath, amssymb, graphics, setspace}

\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{{}}

% New stuff
\usepackage{environ}
\renewcommand{\pmb}[1]{#1}% Remove bold math
\RenewEnviron{doublespace}{%
  \let\noindent\relax%
  \let\(\relax\let\)\relax%
  \[\BODY\]
}

\let\oldtext\text
\renewcommand{\text}[1]{%
  \ifnum\pdfstrcmp{#1}{Sin}=0
    \cos
  \else\ifnum\pdfstrcmp{#1}{Cos}=0
    \sin
  \else\ifnum\pdfstrcmp{#1}{Tan}=0
    \tan
  \else\ifnum\pdfstrcmp{#1}{==}=0
    \equiv
  \else
    \oldtext{#1}
  \fi\fi\fi\fi
}

\begin{document}

\section*{Define the load (omitting the d$\theta $)}

\begin{doublespace}
\noindent\(\pmb{\text{dP}'=w R;}\)
\end{doublespace}

\section*{Primary Structure; Externally Applied load}

\subsection*{\textup{Determine horizontal reaction at B by taking moment with respect to Z (CCW +ve)}}

\begin{doublespace}
\noindent\(\pmb{\text{x1}=R \text{Cos}[\alpha ]; \text{x2}=R \text{Cos}[\theta ]; \text{y0}=R(1-\text{Sin}[\alpha ]);}\)
\end{doublespace}

\begin{doublespace}
\noindent\(\pmb{\text{SigMZ}= -\text{BX} \text{y0}+\int _{\alpha }^{\pi /2}(\text{x1}-\text{x2}) \text{dP}' d\theta }\)
\end{doublespace}

\begin{doublespace}
\noindent\(\frac{1}{2} R^2 w ((\pi -2 \alpha ) \text{Cos}[\alpha ]+2 (-1+\text{Sin}[\alpha ]))-\text{BX} R (1-\text{Sin}[\alpha ])\)
\end{doublespace}

\begin{doublespace}
\noindent\(\pmb{\text{Sol1}=\text{Solve}[\text{SigMZ}\text{==}0, \text{BX}]; \text{BX}= \text{BX}\text{/.}\text{Sol1}[[1]]}\)
\end{doublespace}

\begin{doublespace}
\noindent\(-\frac{R w (-2+\pi  \text{Cos}[\alpha ]-2 \alpha  \text{Cos}[\alpha ]+2 \text{Sin}[\alpha ])}{2 (-1+\text{Sin}[\alpha ])}\)
\end{doublespace}

\subsection*{\textup{Determine vertical reaction by taking summation of forces in the y direction}}

\begin{doublespace}
\noindent\(\pmb{\text{BY}=\int _{\alpha }^{\pi /2} \text{dP}'d\theta }\)
\end{doublespace}

\begin{doublespace}
\noindent\(R w \left(\frac{\pi }{2}-\alpha \right)\)
\end{doublespace}

\begin{doublespace}
\noindent\(\pmb{\text{CX}=\text{BX}}\)
\end{doublespace}

\begin{doublespace}
\noindent\(-\frac{R w (-2+\pi  \text{Cos}[\alpha ]-2 \alpha  \text{Cos}[\alpha ]+2 \text{Sin}[\alpha ])}{2 (-1+\text{Sin}[\alpha ])}\)
\end{doublespace}

\end{document}

答案2

您可以将整个 Mathematica 笔记本导出为 pdf,然后使用 pdfpage pack 在 latex 文档中使用它

前言:

\usepackage[final]{pdfpages}
.
.
.
\begin{document}

\includepdf[pages=1]{notebook.pdf}

相关内容