有没有带有 LaTeX 语法的计算器?

发布于 2024-07-29 20:27:23 字数 1543 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

怀念你的温柔 2024-08-05 20:27:23

LaTeXCalc 项目就是为了实现这一目标而设计的。 它将读取 TeX 文件并进行计算。 有关更多信息,请查看主页 http://latexcalc.sourceforge.net/

The LaTeXCalc project is designed to do just that. It will read a TeX file and do the computations. For more information check out the home page at http://latexcalc.sourceforge.net/

ˉ厌 2024-08-05 20:27:23

calc 包 允许您在源代码中进行一些计算,但仅限于 \ setcounter\addtolength。 据我所知,这不是你想要的。

如果您已经使用sage,那么sagetex 包非常棒(如果没有,那就太过分了)。 它允许您从输入中获得格式良好的输出,如下所示:

The square of
$\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}$
is \sage{matrix([[1, 2], [3,4]])^2}.

The prime factorization of the current page number is \sage{factor(\thepage)}

The calc package allows you to do some calculations in source, but only within commands like \setcounter and \addtolength. As far as I can tell, this is not what you want.

If you already use sage, then the sagetex package is pretty awesome (if not, it's overkill). It allows you get nicely formatted output from input like this:

The square of
$\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}$
is \sage{matrix([[1, 2], [3,4]])^2}.

The prime factorization of the current page number is \sage{factor(\thepage)}
故笙诉离歌 2024-08-05 20:27:23

正如 Andy 所说,答案是有一个计算器可以理解大多数 Latex 公式:Emacs。

尝试以下步骤(假设普通 emacs):

  1. 打开 emacs
  2. 打开 .tex 文件(或激活乳胶模式)
  3. 将点定位在两个 $$ 之间的某个位置,或者例如在公式(甚至矩阵)的开始/结束环境内。
  4. 使用 calc 嵌入模式以获得最大的效果

因此,使用上面给出的公式中的点:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

Cx * d复制下面一行中的公式并进入 calc-embedded 模式,该模式应该已经为您激活了 calc 的乳胶变体。 您的缓冲区现在看起来像这样:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

$\frac{-37651}{150}

正如 Andy 所说,答案是有一个计算器可以理解大多数 Latex 公式:Emacs。

尝试以下步骤(假设普通 emacs):

  1. 打开 emacs
  2. 打开 .tex 文件(或激活乳胶模式)
  3. 将点定位在两个 $$ 之间的某个位置,或者例如在公式(甚至矩阵)的开始/结束环境内。
  4. 使用 calc 嵌入模式以获得最大的效果

因此,使用上面给出的公式中的点:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

Cx * d复制下面一行中的公式并进入 calc-embedded 模式,该模式应该已经为您激活了 calc 的乳胶变体。 您的缓冲区现在看起来像这样:

请注意,分数已经尽可能地转换了。 再次执行相同操作 (Cx * d) 并按 cf 将小数转换为浮点数,会产生以下缓冲区:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

$\frac{-37651}{150}$

$-251.006666667$

我使用了 Cx * d code> 复制公式,然后进入嵌入模式以获得中间值,但是还有 Cx * e 可以避免重复,只需进入当前公式的嵌入模式。

如果您有兴趣,您应该真正查看 Emacs Calc 的信息页面 -嵌入模式。 一般来说,Gnu Emaca Calculator 的帮助以及很棒的交互式教程

As Andy says, the answer is yes there is a calculator that can understand most latex formulas: Emacs.

Try the following steps (assuming vanilla emacs):

  1. Open emacs
  2. Open your .tex file (or activate latex-mode)
  3. position the point somewhere between the two $$ or e.g. inside the begin/end environment of the formula (or even matrix).
  4. use calc embedded mode for maximum awesomeness

So with point in the formula you gave above:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

press C-x * d to duplicate the formula in the line below and enter calc-embedded mode which should already have activated a latex variant of calc for you. Your buffer now looks like this:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

$\frac{-37651}{150}

As Andy says, the answer is yes there is a calculator that can understand most latex formulas: Emacs.

Try the following steps (assuming vanilla emacs):

  1. Open emacs
  2. Open your .tex file (or activate latex-mode)
  3. position the point somewhere between the two $$ or e.g. inside the begin/end environment of the formula (or even matrix).
  4. use calc embedded mode for maximum awesomeness

So with point in the formula you gave above:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

press C-x * d to duplicate the formula in the line below and enter calc-embedded mode which should already have activated a latex variant of calc for you. Your buffer now looks like this:

Note that the fraction as already been transformed as far as possible. Doing the same again (C-x * d) and pressing c f to convert the fractional into a floating point number yields the following buffer:

$\frac{154,7}{25} - (289 - \frac{1337}{42})$

$\frac{-37651}{150}$

$-251.006666667$

I used C-x * d to duplicate the formula and then enter embedded mode in order to have the intermediate values, however there is also C-x * e which avoids the duplication and simply enters embedded mode for the current formula.

If you are interested you should really have a look at the info page for Emacs Calc - Embedded Mode. And in general the help for the Gnu Emaca Calculator together with the awesome interactive tutorial.

旧人 2024-08-05 20:27:23

我的计算器可以做到这一点。 要获得格式化输出,请双击结果公式并按 ctrl+c 进行复制。

它也可以做相当高级的事情(微分,简单的积分(而不是那么简单的积分)......)。

https://calculator-algebra.org/

计算示例:

https://calculator-algebra.org:8166/#%7B %22当前页%22%3A%22计算器%22%2C%22计算器输入%22%3A%22%5C%5Cfrac%7B1%2B2%7D%7B3%7D%3B%20d%2Fdx(arctan%20(2x%2B3)) %22%2C%22监控%22%3A%22true%22%7D

My calculator can do that. To get the formatted output, double-click the result formula and press ctrl+c to copy it.

It can do fairly advanced stuff too (differentiation, easy integrals (and not that easy ones)...).

https://calculator-algebra.org/

A sample computation:

https://calculator-algebra.org:8166/#%7B%22currentPage%22%3A%22calculator%22%2C%22calculatorInput%22%3A%22%5C%5Cfrac%7B1%2B2%7D%7B3%7D%3B%20d%2Fdx(arctan%20(2x%2B3))%22%2C%22monitoring%22%3A%22true%22%7D

花开半夏魅人心 2024-08-05 20:27:23

您可以在(主要是 TeX,带有一些 R)文件上运行名为 Sweave 的 R 函数,该文件可以用 Tex 中的结果替换 R 表达式。

可以在此处找到教程:http://www.scribd.com/doc/6451985/Learning-to-Sweave-in-APA-Style

You can run an R function called Sweave on a (mostly TeX with some R) file that can replace R expressions with their results in Tex.

A tutorial can be found here: http://www.scribd.com/doc/6451985/Learning-to-Sweave-in-APA-Style

横笛休吹塞上声 2024-08-05 20:27:23

有一种方法可以做你想做的事,只是不完全按照你描述的那样。

您可以使用 fp 包 (\usepackage[options]{fp}) 浮点包将执行您想要的任何操作; 解方程、加除法等等。 不幸的是它不会读取 LaTeX 数学,你必须做一些不同的事情,文档非常差,所以我将在这里举一个例子。

例如,如果您想做 (2x3)/5,您可以输入:

\FPmul\p{2}{3}           % \p is the assignment of the operation 2x3
\FPupn\p{\p{} 7 round}   % upn evaluates the assignment \p and rounds to 7dp
\FPdiv\q{\p}{5}          % divides the assigned value p by 5 names result q
\FPupn\q{\q{} 4 round}   % rounds the result to 4 decimal places and evaluates
$\frac{2\times3}{5}=\FPprint\q$  % This will print the result of the calculations in the math.

FP 命令始终是可见的,只有 FPprint 打印与其关联的结果,这样您的文档就不会混乱,FP 命令可以放置在您希望的任何位置(不是动词) ) 只要它们位于关联的 FPprint 之前。

There is a way to do what you want just not quite how you describe.

You can use the fp package (\usepackage[options]{fp}) the floating point package will do anything you want; solving equations, adding dividing and many more. Unfortunately it will not read the LaTeX math you instead have to do something a little different, the documentation is very poor so I'll give an example here.

for instance if you want to do (2x3)/5 you would type:

\FPmul\p{2}{3}           % \p is the assignment of the operation 2x3
\FPupn\p{\p{} 7 round}   % upn evaluates the assignment \p and rounds to 7dp
\FPdiv\q{\p}{5}          % divides the assigned value p by 5 names result q
\FPupn\q{\q{} 4 round}   % rounds the result to 4 decimal places and evaluates
$\frac{2\times3}{5}=\FPprint\q$  % This will print the result of the calculations in the math.

the FP commands are always ibvisible, only FPprint prints the result associated with it so your documents will not be messy, FP commands can be placed wherever you wish (not verb) as long as they are before the associated FPprint.

天生の放荡 2024-08-05 20:27:23

没有,因为这通常是不可能的。

LaTeX 数学模式标记是表示性标记,在某些情况下它无法提供足够的信息来计算表达式。

这是创建 MathML 内容标记的原因之一,也是在 Mathematica 中使用 MathML 的原因之一。 MathML 实际上是两种语言合二为一:

  • 演示标记
  • 内容标记

要完成您所追求的目标,您必须拥有具有组合演示和内容标记的 MathML(请参阅 MathML 规范)。

在我看来,最好的选择是使用 MathML(即使它很冗长)并在必要时转换为 LaTeX。 也就是说,我也最喜欢 LaTeX 语法,也许我们需要的是 MathML 的紧凑语法(类似于 RelaxNG 紧凑语法)。

There is none, because it is generally not possible.

LaTeX math mode markup is presentational markup and there are cases in which it does not provide enough information to calculate the expression.

That was one of the reasons MathML content markup was created and also why MathML is used in Mathematica. MathML actually is sort of two languages in one:

  • presentation markup
  • content markup

To accomplish what you are after you'll have to have MathML with comibned presentation and content markup (see MathML spec).

In my opinion your best bet is to use MathML (even if it is verbose) and convert to LaTeX when necessary. That said, I also like LaTeX syntax best and maybe what we need is a compact syntax for MathML (something similar in spirit to RelaxNG compact syntax).

风苍溪 2024-08-05 20:27:23

您可以将其粘贴到 symbolab 中,作为奖励,它有免费的分步解决方案。 另外,由于 symbolab 使用 mathquill,它会立即格式化您的乳胶。

You could just paste it into symbolab which as a bonus has free step by step solutions. Also since symbolab uses mathquill it instantly formats your latex.

尘曦 2024-08-05 20:27:23

考虑到 LaTeX 本身是一种图灵完备的标记语言,我强烈怀疑您是否可以构建类似这样的不直接构建到 LaTeX 中的东西。 此外,LaTeX 数学 matkup 本身几乎没有语义意义,它只是描述视觉外观。

话虽如此,您可能可以将一些东西组合在一起,识别 LaTeX 数学标记的不可编程子集,并以相同的方式输出结果。 如果您感兴趣的只是分数和整数的简单算术(不过要小心小数,因为它们在德语文本中可能显示为 3{,}141... :))别太难了。 但一旦你从积分、矩阵等开始,我担心 LaTeX 缺乏表达能力来准确描述你的意图。 毕竟,它是一个文档准备系统,因此不太适合作为计算机代数系统的输入。

旁注:您可以切换到 Word,它在当前版本中具有一种数学标记语言,该语言与 LaTeX 非常类似(现在它甚至支持 LaTeX 标记),但仍然对 Google 友好,以便更简单条款:

 Microsoft Word 中数学标记的插图

使用免费的 Microsoft Math 插件,您甚至可以让 Word 就地计算表达式:

Microsoft Word 的 Microsoft Math 插件的插图,计算表达式

Considering that LaTeX itself is a Turing-complete markup language I strongly doubt you can build something like this that isn't built directly into LaTeX. Furthermore, LaTeX math matkup itself has next to no semantic meaning, it merely describes the visual appearance.

That being said, you can probably hack together something which recognizes a non-programmable subset of LaTeX math markup and spits out the result in the same way. If all you're interested in is simple arithmetics with fractions and integers (careful with decimal fractions, though, as they may appear as 3{,}141... in German texts :)) this shouldn't be too hard. But once you start with integrals, matrices, etc. I fear that LaTeX lacks expressiveness to accurately describe your intentions. It is a document preparation system, after all and thus not very suitable as input for computer algebra systems.

Side note: You can switch to Word which has—in its current version—a math markup language which is sufficiently LaTeX-like (by now it even supports LaTeX markup) and yet still Google-friendly for simpler terms:

Illustration of math markup in Microsoft Word

With the free Microsoft Math add-in you can even let Word calculate expressions in-place:

Illustration of the Microsoft Math add-in for Microsoft Word, calculating an expression

忆悲凉 2024-08-05 20:27:23

为了在 LaTeX 本身中执行数学运算,您还可以查看 pgfmath 包,它比 calc 包更强大、更方便。 您可以从 TikZ 和 PGF 软件包手册的第六部分了解如何使用它,您可以在这里找到它(当前版本 2.10):http://mirror.unl.edu/ctan/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf

For performing the math within your LaTeX itself, you might also look into the pgfmath package, which is more powerful and convenient than the calc package. You can find out how to use it from Part VI of The TikZ and PGF Packages Manual, which you can find here (version 2.10 currently): http://mirror.unl.edu/ctan/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf

一页 2024-08-05 20:27:23

Emacs calc-mode 接受乳胶输入。 我每天都用它。 按“d”,然后按“L”进入乳胶输入模式。 按“'”打开一个提示,您可以在其中粘贴文本。

任何说不可能的人都是错误的。

Emacs calc-mode accepts latex-input. I use it daily. Press "d", followed by "L" to enter latex input mode. Press "'" to open a prompt where you can paste your tex.

Anyone saing it is not possible is wrong.

ゝ杯具 2024-08-05 20:27:23

IIRC Mathematica 可以做到。

IIRC Mathematica can do it.

递刀给你 2024-08-05 20:27:23

没有,因为这通常是不可能的。 LaTeX 数学模式
标记是表示性标记,并且在某些情况下确实如此
没有提供足够的信息来计算表达式。

你是对的。 LaTeX 本身并没有提供足够的信息来进行任何计算。而且,它并不代表任何进行计算的信息。 但是没有人阻止以 LaTeX 格式编写包含此类信息的文本。
这是一条困难的道路,因为您需要构建一个规则系统,叠加在 Latex 格式的文本内容需要包含哪些内容,以便您的解释器可以识别。 然后说服用户有必要学习等等等等......
创建逻辑直观的数学表达式计算器的最简单方法。 并且该表达式已经可以转换为latex。 和你说的差不多。 这是在我指出的程序中实现的。 AnEasyCalc 允许您在任何文本编辑器中键入平面文本时键入表达式。 然后它自己检查、计算并生成 LateX 字符串。 它的工作非常简单和快速。 只要尝试一下,您就会看到这一点。

There is none, because it is generally not possible. LaTeX math mode
markup is presentational markup and there are cases in which it does
not provide enough information to calculate the expression.

You are right. LaTeX as it is does not provide enough info to make any calculations.Moreover, it does not represent any information to do it. But nobody prevents to wright in LaTeX format a text that contains such an information.
It is a difficult path, because you need to build a system of rules superimposed on what content ofthe text in Latex format needs to contain that it would be recognizable by your interpreter. And then convince the user that it is necessary to learn, etc. etc...
The easiest way to create a logical and intuitive calculator of mathematical expressions. And the expression is already possible to convert latex. It's almost like what you said. This is implemented in the program which I have pointed to. AnEasyCalc allows to type an expression as you type the plane text in any text editor. It checks, calculates and generate LateX string by its own then. Its very easy and rapid work. Just try and you will see that.

醉生梦死 2024-08-05 20:27:23

latex2sympy2 Python 库可以解析 LaTeX 数学表达式。

from latex2sympy2 import latex2sympy

tex_str = r"""YOUR TEX MATH HERE"""
tex_str = r"\frac{9\pi}{\ln(12)}+22"  # example TeX math

sympy_object = latex2sympy(tex_str)
evaluated_tex = float(sympy_object.evalf())
print(evaluated_tex)

此 Python 3 代码将 9

The latex2sympy2 Python library can parse LaTeX math expressions.

from latex2sympy2 import latex2sympy

tex_str = r"""YOUR TEX MATH HERE"""
tex_str = r"\frac{9\pi}{\ln(12)}+22"  # example TeX math

sympy_object = latex2sympy(tex_str)
evaluated_tex = float(sympy_object.evalf())
print(evaluated_tex)

This Python 3 code evaluates 9????/ln(12)+22 (in its LaTeX from above) to 33.37842899841745.

The snippet above only handles basic algebraic simplification (math expressions without variables). Since the library converts LaTeX math to SymPy objects, the above code can easily be tweaked and extended to handle much more complicated LaTeX math (including solving derivatives, integrals, etc...).

The latex2sympy2 library can be installed via the pip command: pip install --user latex2sympy2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文