gpt4 book ai didi

maxima - 编写包含最大值表达式的 LaTeX 代码的文本文件

转载 作者:行者123 更新时间:2023-12-04 14:25:31 27 4
gpt4 key购买 nike

假设在 (wx)Maxima session 中我有以下内容

f:sin(x);
df:diff(f,x);

现在我想让它输出一个包含类似内容的文本文件,例如

If $f(x)=\sin(x)$, then $f^\prime(x)=\cos(x)$.

我找到了 textex1 函数,但我认为我需要一些额外的字符串处理才能执行我想要的操作。

感谢任何帮助。

编辑:进一步说明。

Auto Multiple Choice是一款帮助您创建和管理问卷的软件。要声明问题,可以使用 LaTeX 语法。来自AMC的documentation ,一个问题看起来像这样:

\element{geographie}{
\begin{question}{Cameroon}
Which is the capital city of Cameroon?
\begin{choices}
\correctchoice{Yaoundé}
\wrongchoice{Douala}
\wrongchoice{Abou-Dabi}
\end{choices}
\end{question}
}

可以看出,它只是 LaTeX。现在,稍加修改,我就可以将这个例子变成一道数学题

\element{derivatives}{
\begin{question}{trig_fun_diff_1}
If $f(x)=\sin(x)$ then $f^\prime(0)$ is
\begin{choices}
\correctchoice{$1$}
\wrongchoice{$-1$}
\wrongchoice{$0$}
\end{choices}
\end{question}
}

这就是我想要的那种输出。比方说,我会有一个函数列表,然后执行一个循环来计算它们的导数等等。

最佳答案

好的,回答您更新后的问题。我的建议是将问题和答案作为表达式来处理——首先构建问题列表,然后当列表具有所需的结构时,最后一步输出 TeX 文件。使用表达式通常比使用字符串更清晰、更简单。

例如这是一个简单的方法。我将使用 defstruct 来定义一个结构,以便我可以按名称引用它的各个部分。

defstruct (question (name, datum, item, correct, incorrect));

myq1 : new (question);
myq1@name : "trig_fun_diff_1";
myq1@datum : f(x) = sin(x);
myq1@item : 'at ('diff (f(x), x), x = 0);
myq1@correct : 1;
myq1@incorrect : [0, -1];

你也可以这样写

myq1 : question ("trig_fun_diff_1", f(x) = sin(x), 
'at ('diff (f(x), x), x = 0), 1, [0, -1]);

我不知道哪种形式对你来说更方便。

然后你可以做一个类似这样的输出函数:

tex_question (q, output_stream) :=
(printf (output_stream, "\\begin{question}{~a}~%", q@name),
printf (output_stream, "If $~a$, then $~a$ is:~%", tex1 (q@datum), tex1 (q@item)),
printf (output_stream, "\\begin{choices}~%"),
/* make a list comprising correct and incorrect here */
/* shuffle the list (see random_permutation) */
/* output each correct or incorrect here */
printf (output_stream, "\\end{choices}~%"),
printf (output_stream, "\\end{question}~%));

其中 output_streamopenw(参见)返回的输出流。

可能需要尝试一些不同的东西才能让导数以您想要的格式输出。我的建议是将其逻辑放入输出函数中。

使用表达式的一个副作用是可以直接输出一些不同于 TeX 的表示形式(例如纯文本、XML、HTML)。这对您的项目可能很重要,也可能不重要。

关于maxima - 编写包含最大值表达式的 LaTeX 代码的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45883281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com