WxMaxima 是電腦代數系統(CAS) Maxima 的圖形使用者介面(GUI)。藉助 WxMaxima 可以使用 Maxima 的全部功能。此外,它還為最常用的功能提供了方便的精靈。本手冊介紹了一些使 wxMaxima 成為 Maxima 最受歡迎的圖形介面之一的功能。
在開放原始碼領域,大型系統通常會被拆分為若干較小的專案,以便小型開發團隊更容易管理。例如,一個光碟燒錄程式會由一個真正負責燒錄光碟的命令列工具和一個圖形使用者介面組成,後者讓使用者無需瞭解所有命令列開關、甚至完全不用命令列就能使用它。這種方式的一個優點是,投入到命令列程式中的開發工作可以被許多程式共享:同一個命令列燒錄程式既可以用作檔案管理器的「傳送到光碟」外掛,也可以用作音樂播放器的「燒錄到光碟」功能,還可以用作 DVD 備份工具的燒錄元件。另一個優點是,把一個大任務拆分為較小的部分,使開發者能夠為同一個程式提供多種使用者介面。
一個像 Maxima 這樣的電腦代數系統(CAS,computer algebra system)也適合前述框架。Maxima 可以用作任意精度計算器程式的底層軟體,也可以在更大計算系統中作為公式轉換程式來幫助計算(例如 Sage)。Maxima 也可以直接作為獨立的計算系統使用,它可以透過命令列來存取。然而,在通常情況下,像 wxMaxima 這樣的使用者介面是使用 Maxima 的一種更有效的方法,特別是對於新手而言更是如此。
Maxima 是一個功能齊全的電腦代數系統(CAS)。CAS 是一個程式,它可以透過對公式變形並找到問題的解來求解數學問題,而不是僅僅輸出結果的數值。換言之,Maxima 可以作為一個計算器,給出變數的數值表示,也可以提供解析解。此外,它還提供了一系列數值分析方法,用於求解沒有解析解的方程或方程組。
Maxima 的詳盡文件可以 在網際網路上取得。其中一部分文件也可以透過 wxMaxima 的說明選單存取。按下說明鍵(在大多數系統上是 F1 鍵)時, wxMaxima 的上下文相關說明會自動跳轉到 Maxima 手冊中介紹游標所在命令的頁面。
WxMaxima is a graphical user interface that provides the full functionality and flexibility of Maxima. WxMaxima offers users a graphical display and many features that make working with Maxima easier. For example wxMaxima allows one to export any cell’s contents (or, if that is needed, any part of a formula, as well) as text, as LaTeX or as MathML specification at a simple right-click. Indeed, an entire workbook can be exported, either as a HTML file, as a LaTeX file or as a Typst file. Documentation for wxMaxima, including workbooks to illustrate aspects of its use, is online at the wxMaxima help site, as well as via the help menu.
在 wxMaxima 中輸入的計算式是由 Maxima 命令列工具在背景執行的。
wxMaxima 的大部分功能一看就懂,但有些細節需要注意。 這個網站 提供了許多介紹 wxMaxima 各方面功能的工作表。學習其中的一些(尤其是「10 分鐘 (wx)Maxima 教學」)有助於熟悉 Maxima 的內容以及如何使用 wxMaxima 與 Maxima 互動。本手冊著重介紹 wxMaxima 中那些不太直觀、線上資料中也可能未涉及的方面。
wxMaxima 為數不多的非標準之處之一,是它把交給 Maxima 的資料組織成單元,只有在使用者要求時才對其求值(也就是傳送給 Maxima)。對單元求值時,該單元中的所有命令(且僅限該單元)會作為一批被求值。(這種說法並不完全準確:可以選取若干相鄰的單元一起求值,也可以讓 Maxima 一次性對工作表中的所有單元求值。) WxMaxima 提交命令執行的方式初看可能有些陌生。但它大大簡化了大型文件的處理(使用者並不希望每次修改都自動觸發整個文件的重新求值)。此外,這種方式也非常便於除錯。
如果輸入文字到 wxMaxima 中,則會自動建立一個新的工作表單元。可以在工具列中選擇此單元的類型。如果建立了一個(數學)程式碼單元,則可以將該單元傳送到 Maxima,這將使得計算結果顯示在程式碼下方。下面顯示了一對這樣的命令:
對輸入單元的內容求值時, Maxima
會為該輸入分配一個標籤(預設以紅色顯示,可透過 %i
識別),之後在 wxMaxima 工作階段中可以透過這個標籤引用它。
Maxima 產生的輸出也會得到一個以 %o
開頭的標籤,該標籤預設隱藏,除非使用者為輸出指定了名稱;此時預設顯示使用者定義的標籤。不過
Maxima 自動產生的 %o 式標籤仍然可以使用。
除了(數學)輸入單元外,wxMaxima 中還可以使用文字單元、圖片單元、標題單元、節單元和小節單元等。每個單元都有獨立的復原緩衝區,因此透過更改多個單元的內容,然後逐步復原不需要的更改來進行除錯,是非常容易的。此外,工作表本身有一個全域性復原緩衝區,可以復原單元編輯、新增和刪除操作。
下圖顯示了不同的單元類型(標題單元、節單元、小節單元、文字單元、輸入/輸出單元和圖片單元):
工作表由單元組成。WxMaxima 支援以下幾種單元類型:
當輸入文字時,wxMaxima 的預設行為是自動建立一個數學單元。可以使用「單元」選單、選單中顯示的熱鍵或工具列中的下拉選單建立其他類型的單元。一旦建立了非數學單元,輸入到文件的任何內容都將被解釋為文字。
數學單元中可以包含(C 風格的) 註解文字,寫法如下:
/* This comment will be ignored by Maxima */
「/*」表示註解的開始,「*/」表示註解的結束。
如果使用者試圖選取一個完整的句子,文書處理軟體會嘗試把選區自動擴展到以單字邊界開始和結束。同樣,如果選取了不止一個單元, wxMaxima 會把選區擴展到完整的單元。
不同尋常的是, wxMaxima 透過定義兩種游標來提供拖放的靈活性。 WxMaxima 會在需要時自動在兩者之間切換:
啟動 wxMaxima
時,只會看到閃爍的水平游標。開始輸入後,會自動建立一個數學單元,游標也會變成普通的垂直游標(作為提示符會顯示一個向右的箭頭;數學單元求值(CTRL+ENTER)後,會顯示標籤,例如
(%i1)、 (%o1))。
開始建立工作表時,您也許想先建立另一種類型的單元(使用「單元」選單),例如標題單元或文字單元,用來說明接下來要做什麼。
The cell the cursor is in can be turned into another type with the keyboard: CTRL+SHIFT+1 makes it a text cell, 2 to 7 make it a title, section, subsection, subsubsection, heading 5 or heading 6, the same numbers that insert these cells with CTRL alone, and CTRL+SHIFT+ESC makes it a code cell.
在不同單元之間移動時,也會看到(閃爍的)水平游標,可以在該位置向工作表插入單元(直接開始輸入公式即可插入數學單元,或者透過選單插入其他類型的單元)。
按下 CTRL+ENTER、 SHIFT+ENTER 或數字鍵盤上的 ENTER 鍵,即可執行程式碼單元中的命令。 wxMaxima 預設在按下 CTRL+ENTER 或 SHIFT+ENTER 時傳送命令,但也可以把 wxMaxima 設定為按下 ENTER 即執行命令。
WxMaxima 具有自動完成功能,可透過選單(單元/自動完成)或按組合鍵 CTRL+SPACE 觸發。自動完成會考慮上下文。例如,在 ezUnits 的單位說明中觸發時,它會列出適用的單位。
除了完成檔名、單位名或當前的命令名、變數名之外,自動完成還能為大多數命令顯示一個範本,指明該命令所需引數的類型(和含義)。要使用此功能,請按 SHIFT+CTRL+SPACE 或選擇相應的選單項(單元/顯示範本)。
電腦一般以 8 位值(8-bit)儲存字元,所以最多可以儲存 256 個不同字元。大部分語言中的所有字母、數字和控制符號(傳輸結束、字串結束、為選單繪製矩形的線條和邊緣等)都符合該限制。
然而,對大多數國家而言,所選的 256 個字元的內碼表並不包含數學中常用的希臘字母等字元。為了克服這類限制,人們發明了 Unicode:這種編碼讓英文文字照常工作,同時又能使用遠多於 256 個的字元。
如果 Maxima 是用支援 Unicode 或者不在乎字元編碼的 Lisp 編譯器編譯的,它就支援 Unicode。這兩個條件中至少有一個很可能成立。 WxMaxima 提供了一種用鍵盤輸入希臘字母的方法:
| 按鍵 | 希臘字母 | 按鍵 | 希臘字母 | 按鍵 | 希臘字母 |
|---|---|---|---|---|---|
| a | alpha | i | iota | r | rho |
| b | beta | k | kappa | s | sigma |
| g | gamma | l | lambda | t | tau |
| d | delta | m | mu | u | upsilon |
| e | epsilon | n | nu | f | phi |
| z | zeta | x | xi | c | chi |
| h | eta | om | omicron | y | psi |
| q | theta | p | pi | o | omega |
| A | Alpha | I | Iota | R | Rho |
| B | Beta | K | Kappa | S | Sigma |
| G | Gamma | L | Lambda | T | Tau |
| D | Delta | M | Mu | U | Upsilon |
| E | Epsilon | N | Nu | P | Phi |
| Z | Zeta | X | Xi | C | Chi |
| H | Eta | Om | Omicron | Y | Psi |
| T | Theta | P | Pi | O | Omega |
也可以使用「希臘字母」側邊欄輸入希臘字母。
有些拉丁字母看起來和希臘字母一樣,例如拉丁字母「A」和希臘字母「Alpha」。雖然它們看起來完全相同,卻是兩個不同的 Unicode 字元,由不同的 Unicode 碼位(數字)表示。
如果給變數 A 賦了值,之後又用希臘字母 Alpha 來操作這個變數,就可能出現問題,在列印輸出中尤其如此。 希臘字母 mu(也用作「微」的詞頭)同樣有兩個不同的 Unicode 碼位。
因此,「希臘字母」側邊欄提供了一個選項,可以不提供外觀相似的字元(可透過右鍵選單更改)。
用同樣的方法還可以輸入一些其他的數學符號:
| 輸入的按鍵 | 數學符號 |
|---|---|
| hbar | 普朗克常數:上方帶橫線的 h |
| Hbar | 上方帶橫線的 H |
| 2 | 平方 |
| 3 | 三次方 |
| /2 | 1/2 |
| partial | 偏導數符號(dx/dt 中的 d) |
| integral | 積分號 |
| sq | 平方根 |
| ii | 虛數單位 |
| ee | 元素 |
| in | 屬於 |
| impl implies | 蘊含 |
| inf | 無窮大 |
| empty | 空集 |
| TB | 向右的大三角形 |
| tb | 向右的小三角形 |
| and | 與(and) |
| or | 或(or) |
| xor | 異或(xor) |
| nand | 與非(nand) |
| nor | 或非(nor) |
| equiv | 等價於 |
| not | 非(not) |
| union | 並集 |
| inter | 交集 |
| subseteq | 子集或相等 |
| subset | 子集 |
| notsubseteq | 不是子集也不相等 |
| notsubset | 不是子集 |
| approx | 約等於 |
| propto | 正比於 |
| neq != /= or # | 不等於 |
| +/- or pm | 正負號 |
| <= or leq | 小於或等於 |
| >= or geq | 大於或等於 |
| << or ll | 遠小於 |
| >> or gg | 遠大於 |
| qed | 證畢 |
| nabla | nabla 運算元 |
| sum | 求和號 |
| prod | 求積號 |
| exists | 存在符號 |
| nexists | 不存在符號 |
| parallel | 平行符號 |
| perp | 垂直符號 |
| leadsto | 導致符號 |
| -> | 向右箭頭 |
| –> | 長向右箭頭 |
也可以使用「Symbols」側邊欄輸入這些數學符號。
如果某個特殊符號不在清單中,可以按 ESC [字元編號(十六進位制)] ESC 輸入任意 Unicode 字元。此外,「Symbols」側邊欄還有一個右鍵選單,可以顯示所有可用 Unicode 符號的清單,這些符號可以新增到該工具列或工作表中。
ESC61ESC therefore
results in an a. While you type the number, the list of
symbols shows the character it stands for and its Unicode name.
If the number also is the beginning of a symbol’s name
(be could be the start of beta, or the
character ¾ with the number be), the name wins. A leading
0 or u+ makes it a number:
ESCu+beESC and
ESC00beESC both result in a
¾.
A letter with an accent that Unicode has no character of its own for,
like a t with a bar on top of it, is a letter followed by a “combining”
accent:
tESC304ESC
results in t̄, which Maxima treats as a variable
name like any other.
Symbols one needs often can be added to the “Symbols” sidebar in the “Options” tab of the configuration dialog (Edit -> Configure), where they can also be given a keyboard shortcut. A letter with accents counts as one symbol there and gets one button. The Greek letters and the symbols the sidebars show anyway can be given a keyboard shortcut there, too, or by right-clicking their button in the sidebar. A shortcut has to contain Ctrl or Alt or be a function key, and types its symbol while the worksheet has the keyboard focus. The configuration dialog warns if a menu entry already uses the same keys.
請注意,這些符號中的大多數(邏輯符號是明顯的例外)在 Maxima 中並沒有特殊含義,因此會被當作普通字元處理。如果 Maxima 是用不支援 Unicode 字元的 Lisp 編譯的,這些符號可能會導致錯誤訊息。
有可能出現所選字型不包含希臘字母或數學符號等字元的情況,此時這些字元無法顯示。 要解決這個問題,請選擇其他字型(透過:編輯 -> 設定 -> 樣式)。
wxMaxima will replace several Unicode characters with their
respective Maxima expressions, e.g. ² with ^2,
³ with ^3, ≠ with #
or ≤ with <=.
Unicode characters that stand for a Maxima name are instead defined
as Maxima aliases of that name when wxMaxima starts
Maxima: π for %pi, ⅈ for
%i, ⅇ for %e, ∞ for
inf, the (mathematical) Sigma sign (which is not the same
Unicode character as the corresponding Greek letter) for
sum, ∏ for product,
∫ for integrate, the square root sign for
sqrt and ⋀, ⋁, ⊻,
⊼, ⊽, ⇒, ⇔ and
¬ for and, or, xor,
nand, nor, implies,
equiv and not. This means they work in files
loaded by batch() or load(), too, and
aliases lists the names they stand for. As Maxima
reads these characters as letters they need to be separated from
neighbouring names by spaces in such a file: a⋀b is a
variable name, a ⋀ b means a and b. In an
input cell wxMaxima adds these spaces automatically. It also puts
parenthesis around a number or a variable that directly follows the
square root sign, so √2 means sqrt(2).
Unicode 中有幾個「常用」分數被編碼為單個碼位:
¼, ½, ¾, ⅐, ⅑, ⅒, ⅓, ⅔, ⅕, ⅖, ⅗, ⅘, ⅙, ⅚, ⅛, ⅜, ⅝, ⅞
在把輸入傳送給 Maxima 之前,wxMaxima 會把它們替換為 Maxima
中的表示形式,例如 (1/4)。此外還有
⅟,會被替換為 1/;以及
↉(用於棒球),會被替換為 (0/3)。
建議在輸入單元中使用 Maxima 程式碼(而不是這些
Unicode 碼位)。理由:(a) 用於數學輸入的字型可能不包含這些字元;(b)
如果把文件儲存為 wxm 檔案,通常可以被(命令列)Maxima
讀取,而這些替換在命令列 Maxima
中當然不起作用。不過,從其他文件複製貼上公式時,可能會出現這些字元。
透過側邊欄可以存取最重要的 Maxima 命令的捷徑、目錄、除錯訊息視窗或最近執行命令的歷史記錄等。可以透過「View」選單啟用它們。它們都可以移動到 wxMaxima 視窗內外的其他位置。另一個有用的側邊欄可以用滑鼠輸入希臘字母。
在「目錄」側邊欄中,只需用滑鼠右鍵按一下某個標題,再選擇更高一級或更低一級的標題類型,即可提升或降低該標題的級別。
一些文書處理軟體和類似的程式能夠識別 MathML 輸入並自動把它插入為可編輯的二維公式,或者(如 LibreOffice)帶有提供「從剪貼簿匯入 MathML」功能的公式編輯器。還有一些程式支援 RTF 數學公式。因此, WxMaxima 在右鍵選單中提供了多個相應的選單項。
Edit → Paste LaTeX/MathML as Maxima Code (also in
the right-click menu) converts a formula from the clipboard into a
Maxima command, for example one copied from a paper, a web page
or an equation editor. LaTeX may come with or without $…$,
\(…\) or \[…\] around it, so
\int_0^1 \frac{\sin x}{x}\,dx becomes
integrate(sin(x)/x,x,0,1). The command goes where the
cursor is, or into a new code cell. MathML pasted into a code cell with
the ordinary Paste is converted the same way, since
nobody wants the XML in a code cell. If MathML copied with Copy
as MathML is pasted back, the result is the original command:
wxMaxima adds it to the MathML as an annotation.
LaTeX and MathML describe what a formula looks like, not what it
means, so the conversion has to interpret it. Fractions, roots, powers,
subscripts (x_1 becomes the name x_1,
a_{n+1} the array element a[n+1]), functions
with or without parentheses (\sin 2x),
\frac{d}{dx}, f'(x), integrals ending in
dx, sums and products with limits,
\lim_{x\to 0}, |x| and matrices are
understood. An e is Euler’s number, but an i
is only the imaginary unit when set upright (\mathrm{i}),
as it more often is an index. A product of a name and parentheses, like
x(y+1), is taken as a product unless the name is
f, g, h or longer than one
letter. Anything without a single meaning, like \pm,
\dots or text, isn’t guessed at: wxMaxima says
what it couldn’t convert instead. Check the command before evaluating
it.
WxMaxima 支援一組不會與數學記號衝突的標準 Markdown 約定,其中之一是專案符號清單。
普通文字
* 一個條目,縮排級別 1
* 縮排級別 1 的另一個條目
* 第二縮排級別的一個條目
* 第二縮排級別的第二個條目
* 第一縮排級別的第三個條目
普通文字
WxMaxima 會把以 >
字元開頭的文字識別為塊引用:
普通文字
> 引文 引文 引文 引文
> 引文 引文 引文 引文
> 引文 引文 引文 引文
普通文字
WxMaxima 的 TeX 和 HTML 輸出還會識別
=>,並把它替換為相應的 Unicode 符號:
cogito => sum.
HTML 和 TeX 匯出還能識別的其他符號有:用於比較的 <=
和
>=、雙向雙箭頭(<=>)、單箭頭(<->、
-> 和 <-),以及表示相應符號的
+/-。TeX 輸出還能識別 << 和
>>。
A web address in a text cell that starts with http://,
https:// or mailto: is shown as a link. Since
clicking into a text cell places the cursor there, a link is followed by
CTRL+clicking it (CMD+clicking on macOS), or by
right-clicking it and choosing “Open Link”; hovering over it shows where
it leads. The HTML export turns it into a link, the TeX export into a
\url{}. Links are always recognized from the text itself,
so nothing about them is stored in the file.
Links in a code cell’s comments (/* ... */) work the
same way. Elsewhere in code, for example inside a string, an address is
Maxima syntax and is not a link.
The same goes for web addresses in Maxima’s output, for
example in a string printed by
print("See https://wxmaxima-developers.github.io/wxmaxima/"):
CTRL+clicking the address or choosing “Open Link” from its
context menu opens it, while a plain click still selects the output.
Text in a text cell, a title or a section heading can be made bold, italic, underlined or struck through. Select the text and press the respective button in the toolbar; pressing the button again removes that formatting from the selection. With nothing selected the button switches the formatting on or off for what is typed next. The buttons are hidden by right-clicking the toolbar and unchecking “Text formatting buttons”. Code cells cannot be formatted: their colors already show the syntax of the code.
Superscript and subscript buttons work the same way: they make the text smaller and raise it above or lower it below the line, as in E = mc² or H₂O. A character cannot be both, so switching one of them on switches the other off. A line that contains a superscript, a subscript or a character that is taller than the font’s usual ones, for example an emoji, gets as much additional room as it needs.
The formatting is saved in .wxmx files. Older versions
of wxMaxima open such a file without the formatting but keep
all of the text. .wxm files, the exports and the clipboard
contain the text without its formatting.
大多數快捷鍵可以在相應選單的文字中找到。由於它們實際上是從選單文字中取得的,所以可以透過 wxMaxima 的翻譯文字進行自訂,以滿足本地使用者的需求,因此我們不在這裡記錄它們。但是,一些快捷鍵或其別名並沒有記錄在選單中:
A cell’s output can be selected, and explored part by part, without a mouse:
如果文字單元以 TeX: 開頭,TeX 匯出會原樣包含
TeX: 標記後面的文字。利用這個功能,可以在 wxMaxima
工作表中輸入 TeX 標記。
Typst is a typesetting system whose
formula syntax is similar to LaTeX’s, but shorter. File →
Export can write a worksheet as a Typst (.typ)
file, and Edit → Copy as Typst (also in the right-click
menu) copies the selection: part of an output becomes a formula between
$ … $, whole cells become what the export makes of them.
The exported document defines two small functions, wxinput
and wxoutput, that put the prompts and labels beside the
input and the output; changing them changes the look of every cell.
Plots and images are written into a folder named after the document,
with _img appended; an animation shows its first frame.
Typst reads a name of several letters as one variable, so names like
abc are exported as strings ("abc"), which
Typst sets upright, and functions it doesn’t know as
op("asinh").
在 wxMaxima 中輸入的內容可以存為以下三種檔案格式之一,以供以後使用:
.mac 檔案是包含 Maxima
命令的普通文字檔案。可以用 Maxima 的 batch() 或
load() 命令,或者 wxMaxima
的「檔案/以批次檔載入」選單項讀取它們。
下面是一個例子。 Quadratic.mac 定義了一個函式,隨後用
wxdraw2d() 產生一張圖。 之後列印檔案
Quadratic.mac 的內容,並對新定義的函式 f()
求值。
注意:雖然檔案 Quadratic.mac 使用的是 Maxima
的常規副檔名(.mac),但它只能被 wxMaxima
讀取,因為命令 wxdraw2d() 是 wxMaxima 對 Maxima
的擴展。(命令列)Maxima 會忽略未知命令
wxdraw2d(),並把它原樣作為輸出列印出來。
可以用 .mac
檔案編寫自己的巨集函式庫。但由於它們不包含足夠的結構資訊,無法作為
wxMaxima 工作階段讀回。
.wxm 檔案包含除 Maxima 輸出之外的整個工作表。在
Maxima 5.38 以上版本中,可以像 .mac 檔案一樣用 Maxima 的
load() 函式讀取它們。嗯,大多數情況下可以。問題(例如
asksign(x))會帶來麻煩,因為答案會寫入 .wxm
檔案(以便載入後可以給出建議),但 Maxima 無法對其求值。 可以用
assume() 宣告 Maxima 想要知道的屬性,從而避免 Maxima
提問。
使用這種純文字格式時,有時無法避免使用了新功能的工作表與舊版本的 wxMaxima 不相容。
這只是一個純文字檔案(可以用文字編輯器開啟),以特殊的 Maxima 註解的形式包含各單元的內容。
它以如下注釋開頭:
/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
/* [ Created with wxMaxima version 24.02.2_DevelopmentSnapshot ] */接下來是各個單元,編碼為 Maxima 註解,例如一個節單元:
/* [wxMaxima: section start ]
Title of the section
[wxMaxima: section end ] */或者(在數學單元中,輸入當然 沒有 被註解掉;輸出不會儲存在
wxm 檔案中):
/* [wxMaxima: input start ] */
f(x):=x^2+1$
f(2);
/* [wxMaxima: input end ] */影像採用 Base64 編碼,第一行是影像類型:
/* [wxMaxima: image start ]
jpg
[very chaotic looking character sequence]
[wxMaxima: image end ] */分頁符號只是一行,內容為:
/* [wxMaxima: page break ] */摺疊的單元用以下標記:
/* [wxMaxima: fold start ] */
...
/* [wxMaxima: fold end ] */這種基於 XML 的檔案格式會儲存完整的工作表,包括縮放比例和監視清單等內容。這是首選的檔案格式。
wxmx
檔案看起來像二進位制格式,但可以用作業系統自帶的工具處理。它是一個 zip
檔案,可以用 unzip
解壓(也許需要先重新命名,以便作業系統的解壓程式能識別它)。
我們沒有使用壓縮功能,只是利用了把多個檔案合併成一個檔案的能力:影像本身已經壓縮過,其餘部分是簡單的文字(很可能比包含的大影像小得多)。
它包含以下檔案:
mimetype:此檔案包含 wxMaxima 檔案的 MIME 類型:
text/x-wxmathmlformat.txt:關於 wxMaxima 和 wxmx
檔案格式的簡短說明content.xml:一個 XML 文件,以 XML
格式包含文件的各個單元。因此,如果出了問題,可以解壓 wxMaxima 文件(也許需要先重新命名為
zip 檔案),用文字編輯器修改 content.xml
檔案,或者替換損壞的影像,再把檔案重新壓縮,並把 zip
重新命名為 wxmx 檔案,這樣就得到了一個修改過的
wxmx 檔案。
對於一些常見的可設定變數,wxMaxima提供了兩種設定方法:
用於新產生動畫的影格率儲存在變數 wxanimate_framerate
中,可以使用設定對話方塊更改此變數在新工作表中的初始值。
下次啟動後,如果 maxima 沒有修改 wxplot_size
的值,內嵌到工作表中的圖形將以此尺寸建立。
如果只想設定單個圖形的尺寸,可以使用以下寫法,它只針對一條命令設定變數的值:
wxdraw2d(
explicit(
x^2,
x,-5,5
)
), wxplot_size=[480,480]$該選項使以下兩個功能生效:
/* is closed by an
inserted */. Typing */ in front of it moves
the cursor past it instead.如果設定了此選項,只有在使用者要求時才會覆蓋工作表所在的檔案。不過,如果發生崩潰、斷電等情況,臨時目錄中仍會保留一份最新的備份。
如果未設定此選項, wxMaxima 的行為更像一個現代手機應用:
The toolbar is made of sections, like the “Open” and “Save” buttons, the evaluation buttons or the drop-down list that sets the type of a cell. The “Toolbar” tab of the configuration dialog lists them in the order the toolbar shows them in: drag a section to another place, or select it and press “Up” or “Down”, to move it, and uncheck it to hide it. The flexible space pushes every section after it to the right edge of the window. “Default order” restores the original arrangement. Sections can also be shown or hidden by right-clicking the toolbar.
The “Page settings” tab of the configuration dialog sets the paper
the worksheet is printed and exported to PDF on: its size and
orientation, the margins (in millimetres) and the print scale, which
makes everything on paper bigger or smaller. Its “Default” tab is what
every document is printed with; its “This document” tab, which
Edit → Page Settings… opens on its own, can give the
current document settings of its own instead. These are saved in the
document’s .wxmx file, so the document is printed on the
same paper wherever it is opened (a .wxm file doesn’t keep
them).
View → Page View shows the worksheet the way it will be printed: it becomes as wide as the printable part of the page, so lines break where they will on paper, a matrix too large for the page is shrunk or split as it will be when printed, images get the size they will have on paper, and a dashed line marks where each page ends. The page view can be switched on and off at any time; it stays on for the next window opened.
在 Unix/Linux 上,設定資訊儲存在您主目錄下的檔案
.wxMaxima 中(如果使用的是 wxWidgets <
3.1.1),或者儲存在 .config/wxMaxima.conf 中((XDG
標準)如果使用的是 wxWidgets >= 3.1.1)。可以透過命令
wxbuild_info(); 或選單項「說明->關於」檢視 wxWidgets
的版本。 wxWidgets 是
wxMaxima 所基於的跨平臺圖形介面庫(名稱中的 wx
即來源於此)。 (由於檔名以點開頭, .wxMaxima 或
.config 是隱藏的。)
當使用 Windows
系統時,設定資訊將儲存在登錄檔中。在登錄檔中的以下位置可以找到 wxMaxima
的相關條目:HKEY_CURRENT_USER\Software\wxMaxima。
WxMaxima 主要是 Maxima 的圖形使用者介面。因此,它的主要任務是把命令傳遞給 Maxima 並報告這些命令的執行結果。但在某些情況下, wxMaxima 也為 Maxima 增加了功能。前面已經提到, WxMaxima 能夠把工作表的內容匯出為 HTML 和 LaTeX 檔案來產生報告。本節介紹 wxMaxima 在工作階段中更好地插入圖形的一些方式。
wxsubscripts 指定 wxMaxima
是否(以及如何)自動把變數名的一部分顯示為下標:
如果它的值為 false,則此功能關閉,wxMaxima
不會把變數名中底線之後的部分自動顯示為下標。
如果它的值為
'all,底線之後的所有內容都會顯示為下標。
如果它的值為 true,形如 x_y
的變數名在以下情況下以下標形式顯示:
x 或 y 是單個字母,或者y 是一個整數(可以包含多個字元)。
A variable the rules above don’t cover can still be declared as “to
be subscripted” using the command
wxdeclare_subscripted(variable_name); or
wxdeclare_subscripted([variable_name1,variable_name2,...]);
Declaring a variable as subscripted can be reverted using the following
command: wxdeclare_subscripted(variable_name,false);, which
also keeps a variable the rules above do cover from being
subscripted.
wxdeclare_subscript(text_snippet); or
wxdeclare_subscript([text_snippet1,text_snippet2,...]);
instead declares a text snippet: every variable whose name ends in an
underscore followed by that snippet is subscripted, however long the two
parts are.
也可以使用選單「View->Autosubscript」設定這些值。
執行時間較長的命令可以在狀態列中向使用者回饋。放在那裡的新回饋會替換舊的回饋(因此可以把它用作進度指示),並且當前傳送給
Maxima 的命令一結束,回饋就會被刪除。即使在可能與普通
Maxima(而不是
wxMaxima)一起使用的庫中,也可以放心使用
wxstatusbar():如果沒有 wxMaxima,
wxstatusbar() 命令只會保持未求值狀態。
for i:1 thru 10 do (
/* 告訴使用者我們進行到哪一步了 */
wxstatusbar(concat("Pass ",i)),
/* (sleep n) 是一個 Lisp 函式,前面加上 */
/* 字元 "?" 即可使用。它會推遲程式的 */
/* 執行(這裡:推遲 3 秒) */
?sleep(3)
)$命令 wxworksheettohtml() 可以在執行中的 Maxima
工作階段裡把當前工作表匯出為 HTML 檔案,便於用指令碼或批處理方式匯出。和
wxstatusbar()
一樣,它可以放心地用在可能也會在普通(主控台) Maxima
中執行的程式碼裡:如果沒有
wxMaxima,該命令只會保持未求值狀態。
wxworksheettohtml("report.html")$
wxworksheettohtml("report.html", flavor="svg", wxmx=true)$相對檔名以 Maxima 的工作目錄為基準解釋。可選的關鍵字選項有:
| 選項 | 取值 | 含義 |
|---|---|---|
flavor |
mathml(預設)、 mathjax、
svg、 bitmap |
匯出頁面中公式的呈現方式 |
wxmx |
false(預設)、 true |
嵌入一份可下載的工作階段 .wxmx 副本 |
The images and the .wxmx copy are written into a folder
named after the HTML file, with _htmlimg appended. If
“Embed images into the .html file” is checked in the Export tab of the
configuration dialog, they are embedded into the HTML file instead, so
it can be mailed as a single file.
flavor 的取值與圖形介面 檔案 → 匯出
對話方塊提供的公式格式相對應: mathml
產生無需聯網的獨立頁面, mathjax 為尚不支援 MathML
的瀏覽器新增 MathJaX 備用方案,而 svg/bitmap
把每個公式渲染為影像。
配套命令 wxworksheettotex() 以同樣的方式匯出為
LaTeX(.tex)檔案:
wxworksheettotex("report.tex")$
wxworksheettotex("report.tex", documentclass="report", documentclassoptions="12pt,a4paper")$| 選項 | 含義 |
|---|---|
documentclass |
覆蓋 LaTeX 的 \documentclass(例如
"article"、 "report") |
documentclassoptions |
覆蓋其選項(例如 "12pt,a4paper") |
wxworksheettopdf() exports the worksheet to a PDF file,
as File → Export does when a .pdf file is
chosen:
wxworksheettopdf("report.pdf")$
wxworksheettopdf("report.pdf", language="de", paper="letter", landscape=true)$| option | meaning |
|---|---|
title |
the document title PDF viewers show (default: the worksheet’s title cell, or the file name) |
language |
the document’s language, e.g. "en" or
"de-AT" (default: the language of wxMaxima’s
menus) |
paper |
a4, a3, a5,
letter or legal (default: the paper of the
page settings) |
landscape |
false, true (default: the orientation of
the page settings) |
The PDF looks like a printout, on the paper, with the margins and the
print scale, of the document’s page settings (see “Page settings and the
page view”). Unlike a printout to a PDF printer, it keeps the text as
text, in the worksheet’s fonts, all of which are embedded in the file;
characters that the worksheet’s fonts lack, Greek letters and
mathematical symbols for example, are taken from another installed font
that has them. The PDF is also tagged: screen readers and other
assistive technology can tell headings, text, code and formulas apart
and read them in the right order. Each formula carries Maxima’s
linear notation of it as its spoken description and its MathML, which
screen readers that understand MathML present as a formula, and each
plot the command that created it. Screen readers need to know the
document’s language to pronounce it, which is what the
language option is for.
因為繪圖功能與圖形密切相關,所以圖形使用者介面理應為原始程式的繪圖功能提供一些擴充內容。
Maxima 通常會讓外部程式 Gnuplot 為它建立的每張圖開啟一個單獨的視窗。由於很多時候把圖形嵌入工作表更方便, wxMaxima 提供了自己的一套繪圖函式,它們與相應的 maxima 函式只有名稱不同:都帶有字首「wx」。
以下繪圖函式都有對應的 wx 版本:
| wxMaxima 的繪圖函式 | Maxima 的繪圖函式 |
|---|---|
wxplot2d() |
plot2d |
wxplot3d() |
plot3d |
wxdraw2d() |
draw2d |
wxdraw3d() |
draw2d |
wxdraw() |
draw |
wximplicit_plot() |
implicit_plot |
wxhistogram() |
histogram |
wxscatterplot() |
scatterplot |
wxbarsplot() |
barsplot |
wxpiechart() |
piechart |
wxboxplot() |
boxplot |
如果 wxm 檔案由(主控台)Maxima
讀取,這些函式會被忽略(並像 Maxima
中其他未知函式一樣作為輸出列印出來)。
如果使用這些函式時遇到問題,請檢查對應的 Maxima
函式是否也存在同樣的問題(例如 wxplot2d() 報錯時,用 Maxima
命令
plot2d()(會在單獨的視窗中開啟圖形)繪製同一張圖試試)。如果問題依然存在,那很可能是
Maxima 的問題,應當在 Maxima 錯誤跟蹤器
中報告。也可能是 Gnuplot 的問題。
如上所述,設定對話方塊提供了一種修改所建立圖形預設尺寸的方法,它設定的是
wxplot_size 的初始值。 wxMaxima
的繪圖例程遵循這個以畫素為單位指定圖形尺寸的變數。隨時可以查詢它,或用它設定後續圖形的尺寸:
wxplot_size:[1200,800]$
wxdraw2d(
explicit(
sin(x),
x,1,10
)
)$如果只想改變單一圖形的大小, Maxima
提供了一種只為當前單元改變屬性的標準方法。此時規格
wxplot_size = [value1, value2] 附加在
wxdraw2d( ) 命令之後,而不是 wxdraw2d
命令的一部分。
wxdraw2d(
explicit(
sin(x),
x,1,10
)
),wxplot_size=[1600,800]$用 wxplot_size 設定內嵌圖形的尺寸,適用於使用
wxplot、 wxdraw、 wxcontour_plot
和 wximplicit_plot 等命令產生的內嵌圖形,以及使用
with_slider_draw 和 wxanimate
命令產生的內嵌動畫。
wxplot_size tells Gnuplot how many pixels to
draw. If a plot is wider than the window, wxMaxima shrinks it
until it fits. If one specific plot is meant to be shown larger, even if
that means it no longer fits on the screen, or smaller than that, the
variable wxplot_scale (default: 1) tells
wxMaxima to show it that many times as large as it would
otherwise:
wxdraw2d(
explicit(
sin(x),
x,1,10
)
),wxplot_scale=2$Unlike a bigger wxplot_size, which makes the text and
lines of a plot smaller in relation to the plot,
wxplot_scale makes everything larger, the text included.
The factor is stored in the worksheet with the plot, so it survives
saving and re-opening the file. It is respected by the same commands as
wxplot_size. If wxMaxima shows plots as scalable
vector graphics (see “Create scalable plots” in the configuration
dialog) they stay sharp at any scale; a bitmap plot gets blurry if it is
enlarged a lot.
A plot that should be wide but not high, for example a waveform, is
better made with wxplot_size: a wider
wxplot_size gives more room for the data, at the same
height and with text of the same size. As such a plot would normally be
shrunk to fit into the window, which makes its text tiny again,
wxplot_scale='native tells wxMaxima to show it at
exactly the size wxplot_size asks for, even if that is
wider than the window:
wxdraw2d(
explicit(
sin(10*x)*exp(-x/3),
x,0,10
)
),wxplot_size=[1600,300],wxplot_scale='native$Gnuplot 似乎沒有提供一種可移植的方法來判斷它是否支援 Cairo
函式庫提供的高品質點陣圖輸出。在 Gnuplot
編譯時使用了該庫的系統上,設定選單中的 pngCairo 選項(可以用變數
wxplot_pngcairo 覆蓋)會啟用反鋸齒和額外的線型。如果在
Gnuplot 不支援的情況下設定了
wxplot_pngCairo,得到的將是錯誤訊息而不是圖形。
如果圖形是用 wxdraw 類命令產生的(此功能不支援
wxplot2d 和 wxplot3d),並且底層
Gnuplot 專案的檔案不是特別大, wxMaxima
會提供一個右鍵選單,可以在互動式 Gnuplot 視窗中開啟該圖形。
plot
視窗中開啟 Gnuplot 的命令主控台在 MS Windows 上有兩個 Gnuplot 程式: gnuplot.exe 和
wgnuplot.exe。 可以在設定選單中設定使用哪一個。
wgnuplot.exe 可以開啟一個主控台視窗,在其中輸入
gnuplot 命令,而 gnuplot.exe
沒有這個功能。遺憾的是,使用 wgnuplot.exe
時,每次準備繪圖都會使 Gnuplot 短暫地「搶走」鍵盤焦點。
三維圖形往往讓人難以讀出定量資料。一個可行的替代方案是把第三個引數交給滑鼠滾輪。
with_slider_draw 命令是 wxdraw2d
的一個變體,它會預先產生多幅圖形,並允許透過移動螢幕上方的滑桿在它們之間切換。
WxMaxima 可以把這個動畫匯出為 GIF 動畫。
with_slider_draw
命令的前兩個引數是用於控制繪圖的變數名稱和變數值的清單,接下來的引數與
wxdraw2d 命令的引數相同:
with_slider_draw(
f,[1,2,3,4,5,6,7,10],
title=concat("f=",f,"Hz"),
explicit(
sin(2*%pi*f*x),
x,0,1
),grid=true
);對三維繪圖而言,類似的功能由命令 with_slider_draw3d
提供,可用引數來旋轉三維圖形:
wxanimate_autoplay:true;
wxanimate_framerate:20;
with_slider_draw3d(
α,makelist(i,i,1,360,3),
title=sconcat("α=",α),
surface_hide=true,
contour=both,
view=[60,α],
explicit(
sin(x)*sin(y),
x,-π,π,
y,-π,π
)
)$如果重要的是圖的大致形狀,那麼只要稍微移動一點,就可以直觀地看出它的三維特徵:
wxanimate_autoplay:true;
wxanimate_framerate:20;
with_slider_draw3d(
t,makelist(i,i,0,2*π,.05*π),
title=sconcat("α=",α),
surface_hide=true,
contour=both,
view=[60,30+5*sin(t)],
explicit(
sin(x)*y^2,
x,-2*π,2*π,
y,-2*π,2*π
)
)$with_slider_draw and with_slider_draw3d
make each frame out of a single 2D or 3D scene.
with_slider_draw_bare instead hands the arguments that
follow the variable and its values to a plain draw command.
Each frame can therefore consist of several gr2d and
gr3d scenes, and draw’s global options like
columns or dimensions can be used as well:
with_slider_draw_bare(
f,[1,2,3,4,5],
columns=2,
gr2d(
title=concat("f=",f),
explicit(sin(f*x),x,0,2*π)
),
gr3d(
explicit(sin(f*x)*cos(y),x,0,2*π,y,0,2*π)
)
);Like with_slider_draw,
with_slider_draw_bare accepts
file_name="name", which saves the animation as
name.gif in Maxima’s working directory. As
draw cannot turn a frame of several scenes into a single
frame of a gif, wxMaxima assembles that gif from the frames it shows,
and the animation is still shown in the worksheet. The gif file is only
written when the command is evaluated in wxMaxima.
對於更熟悉 plot 而不是 draw
的使用者,還有第二組函式:
with_slider 和wxanimate。通常,動畫以 wxMaxima
設定中選定的影格率回放或匯出。要設定單個動畫的回放速度,可以使用變數
wxanimate_framerate:
wxanimate(a, 10,
sin(a*x), [x,-5,5]), wxanimate_framerate=6$動畫函式使用 Maxima 的 makelist
命令,因此也有同樣的陷阱:只有當滑桿變數直接出現在表示式中時,它的值才會被代入表示式。因此下面的例子會失敗:
f:sin(a*x);
with_slider_draw(
a,makelist(i/2,i,1,10),
title=concat("a=",float(a)),
grid=true,
explicit(f,x,0,10)
)$如果明確要求 Maxima 代入滑桿的值,繪圖就能正常進行:
f:sin(a*x);
with_slider_draw(
b,makelist(i/2,i,1,10),
title=concat("a=",float(b)),
grid=true,
explicit(
subst(a=b,f),
x,0,10
)
)$這是 Maxima 的一個特性(在支援它的環境中),並不是由 wxMaxima 提供的,但有時會很方便。下面的例子來自 Mario Rodriguez 發到 Maxima 郵件清單的一篇帖子:
load(draw);
/* 在第 1 個視窗中繪製拋物線 */
draw2d(terminal=[wxt,1],explicit(x^2,x,-1,1));
/* 在第 2 個視窗中繪製拋物線 */
draw2d(terminal=[wxt,2],explicit(x^2,x,-1,1));
/* 在第 3 個視窗中繪製旋轉拋物面 */
draw3d(terminal=[wxt,3],explicit(x^2+y^2,x,-1,1,y,-1,1));也可以在同一個視窗中繪製多幅圖形(在命令列 Maxima 中用標準的
draw() 命令同樣可以做到):
wxdraw(
gr2d(
key="sin (x)",grid=[2,2],
explicit(sin(x),x,0,2*%pi)),
gr2d(
key="cos (x)",grid=[2,2],
explicit(cos(x),x,0,2*%pi))
);「Plot using Draw」側邊欄中隱藏著一個簡單的程式碼產生器,用它可以產生場景,從而利用 maxima 自帶的 draw 套件的一部分靈活性。
產生繪製二維場景的 draw()
命令的框架。之後需要用產生場景內容的命令來填充這個場景,例如使用「2D」按鈕下面幾行中的按鈕。
「2D」按鈕的一個實用功能是,它可以把場景設定為動畫,其中某個變數(預設是 t )在每一影格中取不同的值:與靜止的三維圖形中的相同資料相比,運動的二維圖形往往更容易解讀。
產生繪製三維場景的 draw()
命令的框架。如果既沒有設定二維場景也沒有設定三維場景,其他所有按鈕都會設定一個二維場景,其中包含該按鈕產生的命令。
在游標當前所在的 draw() 命令中加入 sin(x)、
x*sin(x) 或 x^2+2*x-4
之類表示式的標準圖形。如果沒有 draw
命令,則產生一個包含該圖形的二維場景。每個場景都可以加入任意數量的圖形。
嘗試找出使 y=sin(x)、 y*sin(x)=3 或
x^2+y^2=4 之類表示式成立的所有點,並在游標當前所在的
draw() 命令中繪製所得曲線。如果沒有 draw
命令,則產生一個包含該圖形的二維場景。
將變數(如 t)從下限變化到上限,並在當前繪圖命令中使用兩個表示式(如
t*sin(t) 和
t*cos(t)),以產生曲線上點的橫、縱座標
(x,y)(在三維圖形中,第三個表示式產生豎座標 z)。
繪製多個點,並且可以選擇順次連線它們。點的座標取自清單的清單、二維陣列或為每個軸指定的一個清單或陣列。
在圖形上方繪製標題。
設定座標軸。
(僅用於三維圖形)為當前 draw()
命令中隨後的繪圖命令和/或圖形的底面新增類似於山地地圖上的等高線。此外,這個精靈也可以完全不繪製曲面,只顯示等高線圖。
在圖形的圖例中新增一項,顯示下一個圖形的名稱。空名稱會使後續的圖形不再產生圖例項。
為當前 draw 命令中其後的圖形設定線條顏色。
為當前 draw 命令中其後的圖形設定填充顏色。
彈出設定網格線的精靈。
允許選擇適當數目的點,以兼顧速度與精度(任何繪圖程式都會權衡兩者)。
尤其是在使用高解析度顯示器時,預設字型大小可能非常小。對於基於
draw 的命令,可以用 font=...、
font_size=... 之類的選項設定字型和字型大小,例如:
wxdraw2d(
font="Helvetica",
font_size=30,
explicit(sin(x),x,1,10));對於 plot 類命令(例如 wxplot2d、
wxplot3d),可以用 gnuplot_preamble
命令設定字型和字型大小,例如:
wxplot2d(sin(x),[x,1,10],
[gnuplot_preamble, "set tics font \"Arial, 30\"; set xlabel font \",20\"; set ylabel font \",20\";"]);這會把數字的字型設為字型大小 30 的 Arial,並把 xlabel 和 ylabel 的字型大小設為 20(使用預設字型)。
更多資訊請閱讀 Maxima 和 Gnuplot 的文件。注意:Gnuplot 在較大的字型大小下似乎有問題,參見 wxMaxima issue 1966。
如果使用 .wxmx 檔案格式,把檔案嵌入 wxMaxima
專案就像拖放一樣簡單。但有時(例如圖片的內容可能在工作階段中稍後改變時)更好的做法是讓檔案在求值時載入圖片:
show_image("man.png");在 wxMaxima 的設定對話方塊中可以編輯兩個檔案的命令,這些命令在啟動時被執行:
maxima-init.mac 中包含每次啟動 Maxima
時被執行的命令;wxmaxima-init.mac例如,如果 Gnuplot 安裝在 /opt 中(在 MacOS
上可能如此),可以在這些檔案中加入
gnuplot_command:"/opt/local/bin/gnuplot"$ (或
/opt/gnuplot/bin/gnuplot 或其他任何路徑)。
這些檔案位於 Maxima 使用者目錄中(在 Windows 上通常是
%USERPROFILE%/maxima,在其他系統上是
$HOME/.maxima)。可以用以下命令查出它的位置:
maxima_userdir;
wxsubscripts :告訴 Maxima
是否應將包含底線的變數名(例如
R_150)轉換為帶下標的變數名。有關自動轉換哪些變數名的詳細資訊,請參見
wxdeclare_subscript。wxfilename:此變數包含當前在 wxMaxima
中開啟的檔案的名稱。wxdirname:此變數包含當前在 wxMaxima
中開啟的檔案所在目錄的名稱。wxplot_pngcairo 表示 wxMaxima 是否嘗試使用
Gnuplot 的 pngcairo
終端,它提供更多的線條樣式和更好的整體圖形品質。wxplot_size:定義嵌入繪圖的解析度。wxchangedir:在大多數作業系統上, wxMaxima
會自動把 Maxima
的工作目錄設定為當前檔案所在的目錄。這樣檔案輸入輸出(例如
read_matrix)就無需給出要讀寫檔案的完整路徑。在 Windows
上,此功能有時會導致錯誤訊息,因此可以在設定對話方塊中把它設為
false。wxanimate_framerate:下一個動畫回放的影格率。wxanimate_autoplay:是否在預設情況下自動播放動畫。wxmaximaversion:返回 wxMaxima 的版本號。wxwidgetsversion:返回 wxMaxima 所使用的
wxWidgets 版本。wxdirs:一個結構,包含 wxMaxima
自己使用的路徑,因為這些路徑因維護者、發行版和作業系統而異:
wxdirs@userconfdir:存放使用者設定的目錄。與
maxima_userdir
(見上文)是同一個目錄——兩者指向同一位置,只有當在 .mac
檔案中使用 wxdirs@userconfdir 比使用 Maxima
一側的變數更方便時,它才有用。wxdirs@datadir: wxMaxima
自身資料(圖示、內建的自動完成清單等)的安裝目錄。wxdirs@helpdir:本手冊離線副本的安裝目錄。wxdirs@localedir: wxMaxima
翻譯檔案的安裝目錄。wxdirs@maximalocation: wxMaxima
被設定為啟動的 Maxima 可執行檔案的路徑。函式 table_form() 以比 Maxima
預設輸出例程更易讀的形式顯示二維清單。輸入是一個包含一個或多個清單的清單。與
“print”
命令一樣,即使以美元符號結尾,此命令也會顯示輸出。以分號結束命令時,會得到同樣的表格,外加一個
“done”。
table_form(
[
[1,2],
[3,4]
]
)$正如下一個例子所示,可以在執行 table_form
命令之前建立需要顯示的清單。
此外,由於矩陣是含清單的清單,它也可以用類似的方式轉換為表格。
函式 wx_matrix() 是 Maxima 的 matrix()
命令的包裝,它允許在 wxMaxima 中更靈活地排版矩陣:
wx_matrix( <matrix>, [options] )
lines=true:在單元之間繪製內部分隔線。要在視覺上把標題和資料分開,就需要它。rownames=true:告訴 wxMaxima
矩陣的第一列是標籤。colnames=true:告訴 wxMaxima
矩陣的第一行是標籤。parenstyle=<style>:設定矩陣周圍的括號類型。支援的樣式有:
round ()、 square
[]、 angled <>、
straight || 或 none。oversized=<mode>: Decides how
this one matrix is shown if it is too large for the window, whatever the
option Matrices too large for the window (see below) says:
full draws it in full, elide leaves out its
middle rows and columns, and scroll shows it in a box the
size of the window, with scrollbars of its own.banding=<mode>: Decides whether
every other row and column of this matrix is faintly shaded (see below):
true always shades them, even if the matrix fits the
window, false never does, not even in the window
double-clicking opens, and auto, the default, shades them
only if the matrix is too large for the window.範例:
wx_matrix(matrix(["Name", "Value"], ["X", 10], ["Y", 20]),
lines=true, rownames=true, colnames=true, parenstyle=square);wx_matrix() doesn’t display anything itself: it returns
the matrix with the formatting attached, which is used whenever that
value is displayed. So it can be stored in a variable and displayed
later, formatted, and a matrix ended with $ isn’t displayed
at all. A new matrix calculated from it, for example by adding to it or
transposing it, is displayed the normal way again.
A matrix cannot be broken into lines the way a long sum can. So by
default wxMaxima leaves out the middle rows and columns of a matrix that
is too large for the window and marks the gap with ⋯,
⋮ and ⋱, the way a large matrix is written by
hand. The first and last rows and columns always stay visible, and
hovering the mouse over the matrix tells which rows and columns are not
shown. The option Matrices too large for the window in the
Worksheet tab of the configuration dialog can instead draw such
a matrix in full, which makes the whole worksheet scroll sideways, or
show it in a box the size of the window, with scrollbars of its own;
there the mouse wheel scrolls the worksheet, unless that matrix or
something inside it is selected, and such a matrix is printed with its
middle rows and columns left out. Whether it is elided or shown in a
scrolling box, every other row and column of such a matrix is faintly
shaded, so that a row or a column is easy to follow across it; a matrix
that fits the window stays plain, unless wx_matrix()’s
banding option says otherwise. All of this affects only
what is shown on screen and printed: copying, saving and exporting the
matrix always include every entry. wx_matrix()’s
oversized option overrides that option for a single matrix;
a matrix it asks to scroll is still elided on paper, and exporting a
matrix as an image still always shows all of it. On paper – printing and
the PDF export – a matrix that is drawn in full but is too wide for the
page is shrunk to fit it, though not below 60% of its size; one that
would have to shrink further is split into blocks of columns printed one
below the other, each headed with the numbers of its columns. A matrix
taller than a page continues on the next page between two of its rows.
Double-clicking a matrix that is elided or shown in a scrolling box
opens a window of its own that shows all of it; the window can be
resized and scrolled, and Escape closes it. Ctrl+F in
that window searches the matrix: each match selects the entry it is in
and scrolls it into view, and searching again steps on to the next
matching entry.
WxMaxima 提供了幾個函式,用來收集有關當前系統的錯誤報告資訊:
wxbuild_info() 收集當前執行的 wxMaxima
版本的資訊wxbug_report() 說明如何以及在何處提交錯誤報告。如果 Maxima 的 box() 命令的第二個引數是文字
highlight, wxMaxima
會用紅色前景色顯示它的引數。
用 set_display() 可以設定 wxMaxima 如何渲染輸出。
set_display('xml) 是預設值。此時 Maxima
用一種(機器可讀的)XML 方言與 wxMaxima 通訊(可以在「Raw XML
monitor」側邊欄中看到),並輸出排版美觀的公式,例如漂亮的矩陣、根號、分數等。
set_display('ascii) 使 wxMaxima 像命令列 Maxima 那樣以
ASCII 藝術的形式輸出公式。
set_display('none) 產生「單行」的 ASCII 結果——與命令列
Maxima 中的命令 display2d:false; 效果相同。
WxMaxima 的說明選單提供對 Maxima 和 wxMaxima
手冊、提示、一些範例工作表以及命令列 Maxima 自帶示範(
demo() 命令)的存取。
請注意,示範中會寫道:
At the ’_’ prompt, type ’;’ and <enter> to proceed with the demonstration.
這對命令列 Maxima 是適用的,但在 wxMaxima 中,預設需要用以下按鍵繼續示範: CTRL+ENTER
(這可以在 設定->Worksheet->「Hotkeys for sending commands to maxima」 中設定。)
Help > Troubleshooting checks the things that most often
keep wxMaxima from working: whether it finds Maxima,
whether Maxima starts, connects to wxMaxima, sends its
first prompt and proves that it is the Maxima wxMaxima
started, whether it accepts wxMaxima’s Lisp code and can load
packages and draw, whether its temp directory is usable for
plots, whether gnuplot can draw png and
pngcairo plots, whether wxMaxima can stop
Maxima again, and whether the manuals, the help sidebar, a web
browser, the translations, text in SVG images and the AI sidebar are
available. For that it starts a Maxima of its own, so the
worksheet’s Maxima and anything it is calculating are left
alone. The checks are grouped into pages (Maxima, packages and
plots, help and manuals, user interface), each marked with the symbol of
its most important result: a green check mark if everything works, a red
cross if something doesn’t. Selecting a line tells what was found and,
for a problem, what can be done about it; Copy report puts all
of it on the clipboard, ready to be pasted into a bug report.
Maxima (進行實際數學運算的程式)和 wxMaxima (提供易用的使用者介面)是兩個獨立的程式,它們透過本地網路連線進行通訊。因此,最可能的原因是這個連線由於某種原因無法工作。例如,防火牆的設定可能不僅阻止來自網際網路的未授權連線(或許還會攔截一些通往網際網路的連線),還阻止了同一臺電腦內部的行程間通訊。注意,由於 Maxima 是由 Lisp 處理器執行的,被阻止通訊的行程不一定叫做 “maxima”。開啟網路連線的程式的常見名稱有 sbcl、gcl、ccl、lisp.exe 或類似名稱。
在 Unix 電腦上,另一個可能的原因是為同一臺電腦上兩個程式之間提供網路連線的回送(loopback)網路沒有正確設定。
在內部,大多數現代的基於 XML 的格式都是普通的 zip 檔案。
WxMaxima 不開啟壓縮,因此 .wxmx
檔案的內容可以用任何文字編輯器檢視。
如果把損壞的 .wxmx 檔案重新命名為 .zip
之後,檔案末尾的 zip
簽名仍然完好,大多數作業系統都提供了提取其中所儲存資訊的任意部分的方法。當需要從文書處理文件中恢復原始圖片檔案時,也可以這樣做。即使
zip 簽名已經損壞,也不必絕望:如果 wxMaxima
在儲存時發現出了問題,會留下一個 .wxmx~
檔案,其內容可能會有幫助。
即使沒有這樣的檔案: .wxmx 檔案是一種容器格式,其中的
XML 部分是未經壓縮儲存的。可以把 .wxmx 檔案重新命名為
.txt 檔案,然後用文字編輯器恢復檔案內容中的 XML 部分(它以
<?xml version="1.0" encoding="UTF-8"?> 開頭,以
</wxMaximaDocument>
結尾。在這段文字前後,文字編輯器中會顯示一些無法閱讀的二進位制內容)。
如果把只包含這些內容的文字檔案(例如把這段文字複製貼上到一個新檔案中)儲存為以
.xml 結尾的檔案, wxMaxima
就能從該文件中恢復文字。
通常 wxMaxima
會等整個二維公式傳輸完畢後才開始排版,這樣可以省去多次嘗試排版只完成一部分的方程式的時間。不過,
disp 命令可以立即輸出除錯資訊,而不必等待當前的
Maxima 命令結束:
for i:1 thru 10 do (
disp(i),
/* (sleep n) 是一個 Lisp 函式,前面加上 */
/* 字元 "?" 即可使用。它會推遲程式的 */
/* 執行(這裡:推遲 3 秒) */
?sleep(3)
)$另外,也可以參考上文介紹的 wxstatusbar() 命令。
這意味著 wxMaxima 無法讀取 Maxima 本應指示 Gnuplot 建立的檔案。
這個錯誤的可能原因如下:
implicit_plot),但在嘗試繪圖之前沒有用 Maxima 的
load() 命令載入該套件。maxima_userdir 所指向的目錄中有一個以 .gnuplot
結尾的檔案,其中包含 Maxima 發給 Gnuplot
的指令。因此在排查問題時,這個檔案的內容大多數時候都會有幫助。wxplot_pngcairo 設為 true。.png 檔案。預設情況下,只有當滑桿變數出現在要繪製的表示式中時,它的值才會被代入。使用
subst 命令把滑桿變數代入要繪製的方程即可解決這個問題。在 在工作表中嵌入動畫
一節的末尾可以看到一個例子。
對單元的操作和單元內部的更改均有單獨的復原函式,因此發生這種情況的可能性很低。如果確實是這樣,有如下方法可以恢復資料:
playback();一個可能的原因是,在 wxMaxima 設定對話方塊的「Maxima」分頁中設定的位置找不到 Maxima,因此它根本無法執行。把路徑設定為一個可用的 Maxima 可執行檔案應該就能解決這個問題。
理論上, wxMaxima 可能沒有察覺到 Maxima 已經計算完畢,因此永遠得不到可以向 Maxima 傳送新資料的通知。如果是這種情況,「觸發求值」(Trigger evaluation)可能會讓兩個程式重新同步。
Lisp 編譯器 SBCL
預設帶有一個記憶體限制,使它即使在低端電腦上也能執行。在編譯 Lapack
這樣的大型套件或處理極其龐大的方程清單時,這個限制可能太低了。要放寬限制,可以給
SBCL 傳遞命令列引數
--dynamic-space-size,告訴它應該預留多少兆位元組。32 位
Windows 版 SBCL 最多可以預留 999 MB。在 Windows 上執行的 64 位 SBCL
可以被指示使用超過編譯 Lapack 所需的約 1280 MB 記憶體。
給 Maxima (從而也給 SBCL)傳遞命令列引數的一種方法是 wxMaxima 設定對話方塊中的「Maxima 的附加參數」欄位。
安裝套件 ibus-gtk 應該可以解決此問題. 詳情見 https://bugs.launchpad.net/ubuntu/+source/wxwidgets3.0/+bug/1421558。
如果所使用的 Maxima 基於SBCL,則必須將以下行新增到
.sbclrc 檔案中:
(setf sb-impl::*default-external-format* :utf-8)這個檔案應該放在哪個資料夾取決於系統和安裝方式。不過,任何一個基於 SBCL、在當前工作階段中已經計算過一個單元的 Maxima,在收到下面的命令後都會樂於告訴你它的位置:
:lisp (sb-impl::userinit-pathname)Wayland 顯示伺服器與 wxWidgets 之間似乎存在一些問題。WxMaxima 可能受到影響,例如側邊欄無法移動。
可以(全域)禁用 Wayland 改用 X11,或者只讓 wxMaxima 使用 X
視窗系統,方法是設定: GDK_BACKEND=x11
例如,這樣啟動 wxMaxima:
GDK_BACKEND=x11 wxmaxima
在某些 KDE Plasma
系統上,全域選單欄在被點選時會消失。由於這是全域選單代理的缺陷,避免它的唯一方法是讓
wxMaxima 使用自己的選單欄而不是全域選單欄。方法是設定:
UBUNTU_MENUPROXY=0
從 26.05.0 版開始,如果 wxMaxima 檢測到受影響的系統(KDE、Unity 或使用較舊 wxWidgets 版本的 Ubuntu),會嘗試自動設定這個變數。
如果自動修復失敗,可以手動這樣啟動 wxMaxima:
UBUNTU_MENUPROXY=0 wxmaxima
要麼 wxWidgets 編譯時沒有啟用對 Microsoft webview2 的支援,要麼沒有安裝 Microsoft webview2。
Help/About lists which of the things the integrated browser needs this wxMaxima has and which it is missing; the log window (View/Toggle log window) shows the same list.
HTML 瀏覽器可能是 snap、flatpak 或 AppImage 版本,這些版本通常都無法存取安裝在本地系統上的檔案。另一個原因可能是 maxima 或 wxMaxima 以 snap、flatpak 或其他不允許宿主系統存取其內容的方式安裝。第三個原因可能是沒有安裝 maxima 的 HTML 手冊,而線上手冊又無法存取。
工作表中嵌入的是 .png 檔案。 WxMaxima
允許使用者指定在哪裡產生它們:
wxdraw2d(
file_name="test", /* 會自動加上副檔名 .png */
explicit(sin(x),x,1,10)
);如果要使用其他格式,更簡單的做法是先產生圖片,再把它們匯入工作表:
load("draw");
pngdraw(name,[contents]):=
(
draw(
append(
[
terminal=pngcairo,
dimensions=wxplot_size,
file_name=name
],
contents
)
),
show_image(printf(false,"~a.png",name))
);
pngdraw2d(name,[contents]):=
pngdraw(name,gr2d(contents));
pngdraw2d("Test",
explicit(sin(x),x,1,10)
);使用變數 wxplot_size:
wxdraw2d(
explicit(sin(x),x,1,10)
),wxplot_size=[1000,1000];1 HIToolbox 0x00007ff80cd91726 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 102
2 HIToolbox 0x00007ff80cd912b8 _ZN15MenuBarInstance14EnableAutoShowEv + 52
3 HIToolbox 0x00007ff80cd35908 SetMenuBarObscured + 408
...
這可能是作業系統的問題。禁用選單欄的自動隱藏(系統設定 => 桌面與Dock => 選單欄)也許能解決問題。更多資訊參見 wxMaxima issue #1746。
plot2d
or draw open no window, but print “Broken pipe”A message like
WARNING:
Couldn't write to #<SB-SYS:FD-STREAM for "descriptor 9" {1002FC5EF3}>:
Broken pipe
means that Gnuplot stopped before Maxima could send
it the plot. On MacOS the usual reason is that MacOS blocks a
Gnuplot that was downloaded from the internet: since
Maxima starts Gnuplot in the background, MacOS can’t
ask whether it may run. Starting Gnuplot once from a Terminal,
or allowing it in System Settings => Privacy & Security, tells
MacOS that it may; xattr -r -d com.apple.quarantine
followed by the path of Gnuplot (for example
Gnuplot.app) does the same. See wxMaxima
issue #1461.
XQuartz isn’t needed for plots in separate windows: neither
wxMaxima nor Maxima chooses a Gnuplot
terminal for them, so Gnuplot uses its own default one. That is
qt for a Gnuplot from Homebrew and
aqua (AquaTerm) for one from MacPorts, both of which draw
without XQuartz. Only a Gnuplot that offers nothing
but its x11 terminal, or GNUTERM set to
x11, needs XQuartz. Embedded plots
(wxplot2d, wxdraw and friends) never open a
window and don’t need any of this.
日誌訊息有助於排查問題。WxMaxima 可以記錄許多事件。大多數日誌條目對開發者有用,尤其是在出現問題或缺陷時。如果執行的是「Release」版本, 日誌視窗預設不顯示;如果執行的是開發版本,它預設作為第二個視窗顯示。可以透過選單項「View->Toggle log window」 開啟或關閉這個視窗。
日誌視窗不顯示時,訊息並不會「丟失」:如果之後選擇顯示日誌視窗,就能看到以前的日誌訊息(只要沒有清除它們)。
在提交錯誤報告(或自己查詢缺陷)時,這些訊息可能會有幫助。
使用命令列選項「–logtostderr」時,日誌訊息還可以(額外)輸出到 STDERR。在 Windows 上會為此開啟一個單獨的文字主控台,因為 Windows 圖形介面程式沒有連線標準輸入輸出。
有。使用 LaTeX 巨集套件 “geometry” 指定頁邊距的大小。
可以把下面這一行加入 LaTeX 導言區(例如使用設定對話方塊中的相應欄位:「匯出」->「Additional lines for the TeX preamble」),把頁邊距設為 1cm:
\usepackage[left=1cm,right=1cm,top=1cm,bottom=1cm]{geometry}如果 wxWidgets 足夠新,當作業系統的其餘部分處於暗色模式時,
wxMaxima
會自動進入暗色模式。工作表本身預設使用明亮的背景,但可以另行設定。此外,還有一個
View/Invert worksheet brightness
選單項,可以快速在暗色與明亮的工作表之間切換。
Most images are drawn for a white background, and black line art with a transparent background would be invisible on a dark worksheet. So by default, if the worksheet background is dark, the transparent parts of images are filled with a backdrop color. Its color is the style Backdrop of transparent images in the Style tab of the configuration dialog, and the option Behind transparent parts of images in its Worksheet tab can switch the backdrop off, or draw it on a bright worksheet, too.
WxMaxima 會把一些大任務(例如解析 Maxima 一千多頁的手冊)交給背景任務處理,這通常完全不會被察覺。但在需要這類任務結果的那一刻, wxMaxima 可能需要等待幾秒鐘才能繼續工作。
(其他應用程式也可能出現同樣的問題。)點選「OK」之後翻譯似乎正常。WxMaxima 不僅使用自己的翻譯,也使用 wxWidgets 框架的翻譯。
系統中可能沒有這些區域設定。在 Ubuntu/Debian
系統上可以用以下命令產生它們: dpkg-reconfigure locales
可以在 Unicode 側邊欄中找到這些符號(搜尋「double-struck capital」)。但所選字型也必須支援這些符號。如果它們顯示不正確,請選擇其他字型。
如果使用的是 wxMaxima,Maxima 變數 maxima_frontend
被設定為 wxmaxima。此時 Maxima 變數
maxima_frontend_version 包含 wxMaxima 的版本。
如果沒有使用前端(即使用的是命令列 Maxima),這兩個變數的值為
false。
wx_version_min("26.09.0") returns true if
the running wxMaxima is at least version 26.09.0, and
false if it is older, or if the command runs in command
line Maxima. The parts of the version number are compared as
numbers, so 26.10.0 counts as newer than 26.9.0, and a part that is left
out counts as 0: wx_version_min("26.9") is the same as
wx_version_min("26.09.0"). A development version counts as
the version it will be released as.
wxMaxima 26.08.0 and older don’t know
wx_version_min() yet. There, as with any function
Maxima doesn’t know, the call isn’t an error: it just returns
itself, unevaluated, as wx_version_min("26.09.0"), which is
neither true nor false. So a plain
if wx_version_min("26.09.0") then ... stays unevaluated on
these versions, too. A worksheet that has to work with them as well can
compare the result with true, which gives
false there:
if wx_version_min("26.09.0") = true then
wx_matrix(M, oversized=scroll)
else
M;如果儲存為 wxmx 檔案不成功,可以嘗試把文件儲存為 wxm 檔案(反之亦然)。也可以嘗試移除所有輸出(選單 單元->移除所有輸出)後再儲存,也許是某些意外的輸出在儲存過程中造成了問題。
通常,只需點選桌面圖示或桌面選單項就可以啟動帶有圖形使用者介面的程式。不過,WxMaxima 從命令列啟動時仍提供一些命令列開關。
-v 或 --version:輸出版本資訊。-h 或 --help:輸出簡短的說明文字。-o 或
--open=<str>:開啟作為此命令列開關引數給出的檔名-e 或
--eval:開啟檔案後對公式單元求值。-b or --batch: If the command-line opens a
file all cells in this file are evaluated and the file is saved
afterward. This is for example useful if the session described in the
file makes Maxima generate output files. Batch-processing will
be stopped if wxMaxima detects that Maxima has output
an error and will exit if Maxima asks a question no scripted
answer exists for: Mathematics is somewhat interactive by nature so a
completely interaction-free batch processing cannot always be
guaranteed.-d or --diff: Compare 2 or 3 files
side-by-side using the Diff viewer.--single_process: Open all worksheets from within the
same process.--single_thread: Run all background tasks from within
the main thread.--logtostderr: Log all “debug messages” sidebar
messages to stderr, too.--pipe: Pipe messages from Maxima to stderr.--debug: Enable costly debug checks.--exit-on-error: Close the program on any maxima
error.--language=<lang>: Use this language for the user
interface instead of the one configured in the settings, for example
de, pt_BR or zh_CN. The setting
is not saved. Useful for checking a translation, or for making
screenshots for a translated manual.-f or --ini=<str>: Use the init file
that was given as an argument to this command-line switch-u, --use-version=<str>: Use maxima
version <str>.-l, --lisp=<str>: Use a Maxima
compiled with Lisp compiler <str>.-X, --extra-args=<str>: Allows to
specify extra Maxima arguments-m or --maxima=<str>: allows
specifying the location of the maxima binary--enableipc: Lets Maxima control wxMaxima via
interprocess communications. Use this option with care.--screenshot=<file>: Evaluate the file that is
opened, save a screenshot as <file> once
Maxima is idle and exit. What the screenshot shows is read from
the [Screenshot] group of the configuration file given by
--ini. Used for making the screenshots in this manual; see
info/screenshots/README.md in wxMaxima’s source code.--wxmathml-lisp=<str>: Location of wxMathML.lisp
(if not the built-in should be used, mainly for developers).某些作業系統可能在命令列開關前使用破折號而不是減號。
On Linux and other Unix-like systems wxMaxima installs completions for bash, zsh and fish, so the Tab key completes these options and the names of the files wxMaxima can open.
A successful run exits with status 0. A batch run that had to stop before finishing exits with one of the following statuses instead, so a script that calls wxMaxima can tell why it stopped without reading its log:
90: Maxima reported an error and
--exit-on-error was given.91: Maxima asked a question no scripted answer
exists for.92: The file named on the command line could not be
opened.93: Saving the worksheet failed.94: The data of an image in the worksheet could not be
loaded.95: An image in the worksheet could not be decoded
(only checked with --debug).wxMaxima 主要使用 C++ 程式語言和 wxWidgets 框架 開發,構建系統使用 CMake,還有一小部分用 Lisp 編寫。如果你瞭解這些程式語言,並且想為開放原始碼專案 wxMaxima 提供幫助和貢獻,歡迎在 https://github.com/wxMaxima-developers/wxmaxima 加入 wxMaxima 專案。
但需要的不只是程式設計師!你還可以透過以下方式為 wxMaxima 做貢獻:幫助改進文件、發現並報告缺陷(或許還能提供修復)、建議新功能、幫助把 wxMaxima 或手冊翻譯成你的語言(關於如何翻譯 wxMaxima 和手冊,請閱讀 locale 子目錄 中的 README.md)。
或者在討論論壇中回答其他使用者的問題。
wxMaxima 的原始碼使用 Doxygen 編寫了文件,見 這裡。
本程式幾乎是自給自足的:除了系統函式庫(以及 wxWidgets
函式庫)之外,不需要任何外部依賴(例如圖形檔案或 Lisp 部分,即
wxmathML.lisp 檔案),這些檔案都已包含在可執行檔案中。
如果你是開發者,想在不重新編譯整個程式的情況下試用修改過的
wxmathML.lisp 檔案,可以使用命令列選項
--wxmathml-lisp=<str> 來使用另一個 Lisp
檔案,而不是內建的檔案。