diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e2427101f..648473fbb 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -7,7 +7,7 @@ repos:
- id: check-merge-conflict
- id: debug-statements
stages: [pre-commit]
- exclude: ChangeLog-spell-corrected.diff
+ exclude: ChangeLog-spell-corrected.diff|mathics/builtin/system.py
- id: end-of-file-fixer
stages: [pre-commit]
exclude: ChangeLog-spell-corrected.diff
diff --git a/mathics/builtin/atomic/strings.py b/mathics/builtin/atomic/strings.py
index a8016b14a..21f164b5b 100644
--- a/mathics/builtin/atomic/strings.py
+++ b/mathics/builtin/atomic/strings.py
@@ -269,10 +269,10 @@ class CharacterEncoding(Predefined):
https://reference.wolfram.com/language/ref/$CharacterEncoding.html
- - '$CharacterEncoding'
+
- '\\$CharacterEncoding'
- specifies the default raw character encoding to use for input and \
output when no encoding is explicitly specified. \
- Initially this is set to '$SystemCharacterEncoding'.
+ Initially this is set to '\\$SystemCharacterEncoding'.
See the character encoding current is in effect and used in input and \
@@ -281,7 +281,7 @@ class CharacterEncoding(Predefined):
>> $CharacterEncoding
= ...
- By setting its value to one of the values in '$CharacterEncodings', \
+ By setting its value to one of the values in '\\$CharacterEncodings', \
operators are formatted differently. For example,
>> $CharacterEncoding = "ASCII"; a -> b
@@ -290,13 +290,13 @@ class CharacterEncoding(Predefined):
= ...
Setting its value to 'None' restore the value to \
- '$SystemCharacterEncoding':
+ '\\$SystemCharacterEncoding':
>> $CharacterEncoding = None;
>> $SystemCharacterEncoding == $CharacterEncoding
= True
See also
- :$SystemCharacterEncoding:
+ :\\$SystemCharacterEncoding:
/doc/reference-of-built-in-symbols/atomic-elements-of-expressions/string-manipulation/$systemcharacterencoding/.
"""
@@ -329,7 +329,7 @@ class CharacterEncodings(Predefined):
https://reference.wolfram.com/language/ref/$CharacterEncodings.html
- - '$CharacterEncodings'
+
- '\\$CharacterEncodings'
- stores the list of available character encodings.
@@ -430,6 +430,7 @@ class LetterNumber(Builtin):
= 2
"""
+
# FIXME: put the right unicode characters in a way that the
# following test works...
r"""
@@ -706,9 +707,9 @@ class SystemCharacterEncoding(Predefined):
"""
:WMA link:
- https://reference.wolfram.com/language/ref/$SystemCharacterEncoding.html
+ https://reference.wolfram.com/language/ref/\\$SystemCharacterEncoding.html
- - $SystemCharacterEncoding
+
- \\$SystemCharacterEncoding
- gives the default character encoding of the system.
On startup, the value of environment variable 'MATHICS_CHARACTER_ENCODING' \
@@ -899,7 +900,7 @@ def eval_form(self, expr, form, evaluation: Evaluation, options: dict):
class Transliterate(Builtin):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/Transliterate.html
@@ -955,4 +956,5 @@ class Whitespace(Builtin):
>> StringReplace[" this has leading and trailing whitespace \n ", (StartOfString ~~ Whitespace) | (Whitespace ~~ EndOfString) -> ""] <> " removed" // FullForm
= "this has leading and trailing whitespace removed"
"""
+
summary_text = "sequence of whitespace characters"
diff --git a/mathics/builtin/drawing/drawing_options.py b/mathics/builtin/drawing/drawing_options.py
index 4c7cb7a40..5d7406821 100644
--- a/mathics/builtin/drawing/drawing_options.py
+++ b/mathics/builtin/drawing/drawing_options.py
@@ -318,7 +318,7 @@ class PlotRange(Builtin):
- $max$ - explicit limit for each function.
- {$min$, $max$} - explicit limits for $y$ (2D), $z$ (3D), \
or array values.
-
- {{$x$_$min$, $x$_$max$}, {{$y_min}, {$y_max}} - explicit limits for \
+
- {{$x_{min}$, $x_{max}$}, {{$y_{min}$}, {$y_{max}$}} - explicit limits for \
$x$ and $y$.
diff --git a/mathics/builtin/drawing/graphics3d.py b/mathics/builtin/drawing/graphics3d.py
index 230b72535..3f2c13a57 100644
--- a/mathics/builtin/drawing/graphics3d.py
+++ b/mathics/builtin/drawing/graphics3d.py
@@ -66,7 +66,7 @@ class Graphics3D(Graphics):
:WMA link:https://reference.wolfram.com/language/ref/Graphics3D.html
- - 'Graphics3D[$primitives$, $options$]'
+
- 'Graphics3D'[$primitives$, $options$]
- represents a three-dimensional graphic.
See :Drawing Option and Option Values:
@@ -170,11 +170,11 @@ class Sphere(Builtin):
:WMA link:https://reference.wolfram.com/language/ref/Sphere.html
- - 'Sphere[{$x$, $y$, $z$}]'
+
- 'Sphere'[{$x$, $y$, $z$}]
- is a sphere of radius 1 centered at the point {$x$, $y$, $z$}.
-
- 'Sphere[{$x$, $y$, $z$}, $r$]'
+
- 'Sphere'[{$x$, $y$, $z$}, $r$]
- is a sphere of radius $r$ centered at the point {$x$, $y$, $z$}.
-
- 'Sphere[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}, ... }, $r$]'
+
- 'Sphere'[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}, ... }, $r$]
- is a collection spheres of radius $r$ centered at the points \
{$x1$, $y2$, $z2$}, {$x2$, $y2$, $z2$}, ...
@@ -198,14 +198,14 @@ class Cone(Builtin):
:WMA link:https://reference.wolfram.com/language/ref/Cone.html
- - 'Cone[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}]'
+
- 'Cone'[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}]
- represents a cone of radius 1.
-
- 'Cone[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}, $r$]'
+
- 'Cone'[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}, $r$]
- is a cone of radius $r$ starting at ($x1$, $y1$, $z1$) and ending at \
($x2$, $y2$, $z2$).
-
- 'Cone[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}, ... }, $r$]'
+
- 'Cone'[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}, ... }, $r$]
- is a collection cones of radius $r$.
@@ -247,16 +247,16 @@ class Cuboid(Builtin):
Cuboid also known as interval, rectangle, square, cube, rectangular parallelepiped, tesseract, orthotope, and box.
- - 'Cuboid[$p_min$]'
+
- 'Cuboid'[$p_{min}$]
- is a unit cube/square with its lower corner at point $p_min$.
-
- 'Cuboid[$p_min$, $p_max$]
-
- is a 2d square with with lower corner $p_min$ and upper corner $p_max$.
+
- 'Cuboid'[$p_{min}$, $p_{max}$]
+
- is a 2d square with with lower corner $p_{min}$ and upper corner $p_{max}$.
-
- 'Cuboid[{$p_min$, $p_max$}]'
+
- 'Cuboid'[{$p_{min}$, $p_{max}$}]
- is a cuboid with lower corner $p_min$ and upper corner $p_max$.
-
- 'Cuboid[{$p1_min$, $p1_max$, ...}]'
+
- 'Cuboid'[{$p1_{min}$, $p1_{max}$, ...}]
- is a collection of cuboids.
- 'Cuboid[]' is equivalent to 'Cuboid[{0,0,0}]'.
@@ -300,14 +300,14 @@ class Cylinder(Builtin):
:WMA link:https://reference.wolfram.com/language/ref/Cylinder.html
- - 'Cylinder[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}]'
+
- 'Cylinder'[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}]
- represents a cylinder of radius 1.
-
- 'Cylinder[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}, $r$]'
+
- 'Cylinder'[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}}, $r$]
- is a cylinder of radius $r$ starting at ($x1$, $y1$, $z1$) and ending at \
($x2$, $y2$, $z2$).
-
- 'Cylinder[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}, ... }, $r$]'
+
- 'Cylinder'[{{$x1$, $y1$, $z1$}, {$x2$, $y2$, $z2$}, ... }, $r$]
- is a collection cylinders of radius $r$.
@@ -348,10 +348,10 @@ class Tube(Builtin):
:WMA link:https://reference.wolfram.com/language/ref/Tube.html
- - 'Tube[{$p1$, $p2$, ...}]'
+
- 'Tube'[{$p1$, $p2$, ...}]
- represents a tube passing through $p1$, $p2$, ... with radius 1.
-
- 'Tube[{$p1$, $p2$, ...}, $r$]'
+
- 'Tube'[{$p1$, $p2$, ...}, $r$]
- represents a tube with radius $r$.
diff --git a/mathics/builtin/evaluation.py b/mathics/builtin/evaluation.py
index 80d96bd60..71402e368 100644
--- a/mathics/builtin/evaluation.py
+++ b/mathics/builtin/evaluation.py
@@ -14,18 +14,18 @@
class RecursionLimit(Predefined):
- """
+ r"""
:WMA link:
- https://reference.wolfram.com/language/ref/$RecursionLimit.html
+ https://reference.wolfram.com/language/ref/\$RecursionLimit.html
- - '$RecursionLimit'
+
- '\$RecursionLimit'
- specifies the maximum allowable recursion depth after which a \
calculation is terminated.
- Calculations terminated by '$RecursionLimit' return '$Aborted':
+ Calculations terminated by '\$RecursionLimit' return '\$Aborted':
>> a = a + a
: Recursion depth of 200 exceeded.
= $Aborted
@@ -71,17 +71,17 @@ def evaluate(self, evaluation) -> Integer:
class IterationLimit(Predefined):
- """
- :WMA link:https://reference.wolfram.com/language/ref/$IterationLimit.html
+ r"""
+ :WMA link:https://reference.wolfram.com/language/ref/\$IterationLimit.html
- - '$IterationLimit'
+
- '\$IterationLimit'
- specifies the maximum number of times a reevaluation of an expression may happen.
- Calculations terminated by '$IterationLimit' return '$Aborted':
+ Calculations terminated by '\$IterationLimit' return '\$Aborted':
>> $IterationLimit
= 1000
diff --git a/mathics/builtin/exp_structure/general.py b/mathics/builtin/exp_structure/general.py
index b1462f492..f229b7de5 100644
--- a/mathics/builtin/exp_structure/general.py
+++ b/mathics/builtin/exp_structure/general.py
@@ -235,11 +235,11 @@ class SortBy(Builtin):
- 'SortBy[$list$, $f$]'
- sorts $list$ (or the elements of any other expression) according to \
canonical ordering of the keys that are extracted from the $list$'s \
- elements using $f. Chunks of elements that appear the same under $f \
- are sorted according to their natural order (without applying $f).
+ elements using $f$. Chunks of elements that appear the same under $f$ \
+ are sorted according to their natural order (without applying $f$).
- 'SortBy[$f$]'
-
- creates an operator function that, when applied, sorts by $f.
+
- creates an operator function that, when applied, sorts by $f$.
>> SortBy[{{5, 1}, {10, -1}}, Last]
diff --git a/mathics/builtin/files_io/files.py b/mathics/builtin/files_io/files.py
index c45f6c49d..fe32ff609 100644
--- a/mathics/builtin/files_io/files.py
+++ b/mathics/builtin/files_io/files.py
@@ -52,11 +52,11 @@
class Input_(Predefined):
- """
- :WMA link:https://reference.wolfram.com/language/ref/$Input.html
+ r"""
+ :WMA link:https://reference.wolfram.com/language/ref/\$Input.html
- - '$Input'
+
- '\$Input'
- is the name of the stream from which input is currently being read.
@@ -364,7 +364,7 @@ class Get(PrefixOperator):
- 'Get[$name$, Trace->True]'
- Runs Get tracing each line before it is evaluated.
- 'Settings`$TraceGet' can be also used to trace lines on all 'Get[]' calls.
+ 'Settings`\$TraceGet' can be also used to trace lines on all 'Get[]' calls.
@@ -409,17 +409,17 @@ def eval(self, path: String, evaluation: Evaluation, options: dict):
class InputFileName_(Predefined):
- """
+ r"""
:WMA link:
- https://reference.wolfram.com/language/ref/$InputFileName.html
+ https://reference.wolfram.com/language/ref/\$InputFileName.html
- - '$InputFileName'
+
- '\$InputFileName'
- is the name of the file from which input is currently being read.
- While in interactive mode, '$InputFileName' is "".
+ While in interactive mode, '\$InputFileName' is "".
X> $InputFileName
"""
@@ -1126,7 +1126,7 @@ def eval_n(self, file, types, n: Integer, evaluation: Evaluation, options: dict)
py_n = n.get_int_value()
if py_n < 0:
evaluation.message(
- "ReadList", "intnm", to_expression("ReadList", file, types, m)
+ "ReadList", "intnm", to_expression("ReadList", file, types, n)
)
return
diff --git a/mathics/builtin/forms/__init__.py b/mathics/builtin/forms/__init__.py
index 08079cc3c..4e034b9d1 100644
--- a/mathics/builtin/forms/__init__.py
+++ b/mathics/builtin/forms/__init__.py
@@ -1,11 +1,11 @@
-"""
+r"""
Forms of Input and Output
A Form format specifies the way Mathics Expression input is read or output \
written.
-The variable :$OutputForms':
-/doc/reference-of-built-in-symbols/forms-of-input-and-output/form-variables/$outputforms/ \
+The variable :\$OutputForms':
+/doc/reference-of-built-in-symbols/forms-of-input-and-output/form-variables/\$outputforms/ \
has a list of Forms defined.
See also :WMA link:
diff --git a/mathics/builtin/forms/other.py b/mathics/builtin/forms/other.py
index a89bc08ac..b8af827fe 100644
--- a/mathics/builtin/forms/other.py
+++ b/mathics/builtin/forms/other.py
@@ -1,5 +1,5 @@
-"""
-Forms which are not in '$OutputForms'
+r"""
+Forms which are not in '\$OutputForms'
"""
import re
@@ -13,7 +13,7 @@
class SequenceForm(FormBaseClass):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/SequenceForm.html
@@ -56,7 +56,7 @@ def eval_makeboxes(self, args, form, evaluation, options: dict):
class StringForm(FormBaseClass):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/StringForm.html
diff --git a/mathics/builtin/forms/variables.py b/mathics/builtin/forms/variables.py
index b02500f0d..853f904d0 100644
--- a/mathics/builtin/forms/variables.py
+++ b/mathics/builtin/forms/variables.py
@@ -11,21 +11,21 @@
class PrintForms_(Predefined):
r"""
- - '$PrintForms'
+
- '\$PrintForms'
- contains the list of basic print forms. It is updated automatically when new 'PrintForms' are defined by setting format values.
>> $PrintForms
= ...
- Suppose now that we want to add a new format 'MyForm'. Initially, it does not belong to '$PrintForms':
+ Suppose now that we want to add a new format 'MyForm'. Initially, it does not belong to '\$PrintForms':
>> MemberQ[$PrintForms, MyForm]
= False
Now, let's define a format rule:
>> Format[F[x_], MyForm] := "F<<" <> ToString[x] <> ">>"
- Now, the new format belongs to the '$PrintForms' list
+ Now, the new format belongs to the '\$PrintForms' list
>> MemberQ[$PrintForms, MyForm]
= True
@@ -42,7 +42,7 @@ def evaluate(self, evaluation):
class OutputForms_(Predefined):
r"""
- - '$OutputForms'
+
- '\$OutputForms'
- contains the list of all output forms. It is updated automatically when new 'OutputForms' are defined by setting format values.
diff --git a/mathics/builtin/graphics.py b/mathics/builtin/graphics.py
index 313c6fec9..dbe5bdaaa 100644
--- a/mathics/builtin/graphics.py
+++ b/mathics/builtin/graphics.py
@@ -1393,7 +1393,7 @@ class Inset(Builtin):
'Text[$obj$, $pos$]'
represents an object $obj$ inset in a graphic at position $pos$.
- 'Text[$obj$, $pos$, $$]'
+ 'Text[$obj$, $pos$, $opos$]'
represents an object $obj$ inset in a graphic at position $pos$, \
in away that the position $opos$ of $obj$ coincides with $pos$ \
in the enclosing graphic.
diff --git a/mathics/builtin/kernel_sessions.py b/mathics/builtin/kernel_sessions.py
index 215f76514..67ab4342e 100644
--- a/mathics/builtin/kernel_sessions.py
+++ b/mathics/builtin/kernel_sessions.py
@@ -8,8 +8,8 @@
class Out(Builtin):
- """
- :WMA: https://reference.wolfram.com/language/ref/$Out
+ r"""
+ :WMA: https://reference.wolfram.com/language/ref/\$Out
- '%$k$' or 'Out[$k$]'
- gives the result of the $k$th input line.
diff --git a/mathics/builtin/list/eol.py b/mathics/builtin/list/eol.py
index c9b778f29..38cd26fe1 100644
--- a/mathics/builtin/list/eol.py
+++ b/mathics/builtin/list/eol.py
@@ -424,7 +424,7 @@ class DeleteCases(Builtin):
- returns the elements of $list$ that do not match $pattern$.
- 'DeleteCases[$list$, $pattern$, $levelspec$]'
-
- removes all parts of $list on levels specified by $levelspec$ that match pattern (not fully implemented).
+
- removes all parts of $list$ on levels specified by $levelspec$ that match pattern (not fully implemented).
- 'DeleteCases[$list$, $pattern$, $levelspec$, $n$]'
- removes the first $n$ parts of $list$ that match $pattern$.
diff --git a/mathics/builtin/list/rearrange.py b/mathics/builtin/list/rearrange.py
index 683ec4cf6..8bf1761a1 100644
--- a/mathics/builtin/list/rearrange.py
+++ b/mathics/builtin/list/rearrange.py
@@ -792,7 +792,7 @@ class GatherBy(_GatherOperation):
- 'GatherBy[$list$, {$f$, $g$, ...}]'
- gathers elements of $list$ into sub lists of items whose image \
under $f$ identical. Then, gathers these sub lists again into sub \
- sub lists, that are identical under $g.
+ sub lists, that are identical under $g$.
>> GatherBy[{{1, 3}, {2, 2}, {1, 1}}, Total]
@@ -891,7 +891,7 @@ class PadLeft(_Pad):
pads $list$ to length $n$ by adding 0 on the left.
'PadLeft[$list$, $n$, $x$]'
pads $list$ to length $n$ by adding $x$ on the left.
- 'PadLeft[$list$, {$n1$, $n2, ...}, $x$]'
+ 'PadLeft[$list$, {$n1$, $n2$, ...}, $x$]'
pads $list$ to lengths $n1$, $n2$ at levels 1, 2, ... respectively by adding $x$ on the left.
'PadLeft[$list$, $n$, $x$, $m$]'
pads $list$ to length $n$ by adding $x$ on the left and adding a margin of $m$ on the right.
@@ -929,7 +929,7 @@ class PadRight(_Pad):
pads $list$ to length $n$ by adding 0 on the right.
'PadRight[$list$, $n$, $x$]'
pads $list$ to length $n$ by adding $x$ on the right.
- 'PadRight[$list$, {$n1$, $n2, ...}, $x$]'
+ 'PadRight[$list$, {$n1$, $n2$, ...}, $x$]'
pads $list$ to lengths $n1$, $n2$ at levels 1, 2, ... respectively by adding $x$ on the right.
'PadRight[$list$, $n$, $x$, $m$]'
pads $list$ to length $n$ by adding $x$ on the left and adding a margin of $m$ on the left.
@@ -1360,7 +1360,7 @@ class Tally(_GatherOperation):
the result as a list of pairs {object, count}.
'Tally[$list$, $test$]'
- counts the number of occurrences of objects and uses $test to \
+ counts the number of occurrences of objects and uses $test$ to \
determine if two objects should be counted in the same bin.
diff --git a/mathics/builtin/mainloop.py b/mathics/builtin/mainloop.py
index 49548b498..29cd442f4 100644
--- a/mathics/builtin/mainloop.py
+++ b/mathics/builtin/mainloop.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-"""
+r"""
The Main Loop
An interactive session operates a loop, called the "main loop" in this way:
@@ -16,10 +16,10 @@
There are a variety of "hooks" that allow you to insert functions to be applied to the expressions at various stages \
in the main loop.
-If you assign a function to the global variable '$PreRead' it will be applied with the input that is read in the first \
+If you assign a function to the global variable '\$PreRead' it will be applied with the input that is read in the first \
step listed above.
-Similarly, if you assign a function to global variable '$Pre', it will be applied with the input before processing the \
+Similarly, if you assign a function to global variable '\$Pre', it will be applied with the input before processing the \
input, the second step listed above.
"""
@@ -31,10 +31,10 @@
class HistoryLength(Builtin):
- """
+ r"""
:WMA: https://reference.wolfram.com/language/ref/$HistoryLength
- - '$HistoryLength'
+
- '\$HistoryLength'
- specifies the maximum number of 'In' and 'Out' entries.
@@ -104,10 +104,10 @@ class In(Builtin):
class IOHookPreRead(Builtin):
- """
- :WMA: https://reference.wolfram.com/language/ref/$PreRead
+ r"""
+ :WMA: https://reference.wolfram.com/language/ref/\$PreRead
- - $PreRead
+
- \$PreRead
- is a global variable whose value, if set, is applied to the \
text or box form of every input expression before it is fed to the parser.
@@ -123,15 +123,15 @@ class IOHookPreRead(Builtin):
class IOHookPre(Builtin):
- """
- :WMA: https://reference.wolfram.com/language/ref/$Pre
+ r"""
+ :WMA: https://reference.wolfram.com/language/ref/\$Pre
- - $Pre
+
- '\$Pre'
- is a global variable whose value, if set, is applied to every input expression.
- Set $Timing$ as the $Pre function, stores the elapsed time in a variable,
- stores just the result in Out[$Line] and print a formatted version showing the elapsed time
+ Set 'Timing' as the '\$Pre' function, stores the elapsed time in a variable,
+ stores just the result in 'Out[\$Line]' and print a formatted version showing the elapsed time
>> $Pre := (Print["[Processing input...]"];#1)&
>> $Post := (Print["[Storing result...]"]; #1)&
| [Processing input...]
@@ -156,10 +156,10 @@ class IOHookPre(Builtin):
class IOHookPost(Builtin):
- """
- :WMA: https://reference.wolfram.com/language/ref/$Post
+ r"""
+ :WMA: https://reference.wolfram.com/language/ref/\$Post
- - $Post
+
- '\$Post'
- is a global variable whose value, if set, is applied to every output expression.
"""
@@ -170,10 +170,10 @@ class IOHookPost(Builtin):
class IOHookPrePrint(Builtin):
- """
- :WMA: https://reference.wolfram.com/language/ref/$PrePrint
+ r"""
+ :WMA: https://reference.wolfram.com/language/ref/\$PrePrint
- - $PrePrint
+
- '\$PrePrint'
- is a global variable whose value, if set, is applied to every output expression before it is printed.
"""
@@ -186,10 +186,10 @@ class IOHookPrePrint(Builtin):
class IOHookSyntaxHandler(Builtin):
- """
- :WMA: https://reference.wolfram.com/language/ref/$SyntaxHandler
+ r"""
+ :WMA: https://reference.wolfram.com/language/ref/\$SyntaxHandler
- - $SyntaxHandler
+
- '\$SyntaxHandler'
- is a global variable whose value, if set, is applied to any input string that is found to contain a syntax \
error.
@@ -203,10 +203,10 @@ class IOHookSyntaxHandler(Builtin):
class Line(Builtin):
- """
+ r"""
:WMA: https://reference.wolfram.com/language/ref/$Line
- - '$Line'
+
- '\$Line'
- holds the current input line number.
diff --git a/mathics/builtin/makeboxes.py b/mathics/builtin/makeboxes.py
index 38495f711..f4bc3ba30 100644
--- a/mathics/builtin/makeboxes.py
+++ b/mathics/builtin/makeboxes.py
@@ -22,12 +22,12 @@
class BoxForms_(Predefined):
- """
- :WMA link:https://reference.wolfram.com/language/ref/$BoxForms.html
+ r"""
+ :WMA link:https://reference.wolfram.com/language/ref/\$BoxForms.html
- -
-
- $BoxForms is the list of box formats.
+
- '\$BoxForms'
+
- contains the list of box formats.
>> $BoxForms
diff --git a/mathics/builtin/matrices/constrmatrix.py b/mathics/builtin/matrices/constrmatrix.py
index 1bd4600a3..6a6c5a775 100644
--- a/mathics/builtin/matrices/constrmatrix.py
+++ b/mathics/builtin/matrices/constrmatrix.py
@@ -24,7 +24,7 @@ class BoxMatrix(Builtin):
https://reference.wolfram.com/language/ref/BoxMatrix.html
- - 'BoxMatrix[$s]'
+
- 'BoxMatrix[$s$]'
- Gives a box shaped kernel of size 2 $s$ + 1.
@@ -90,7 +90,7 @@ class DiamondMatrix(Builtin):
:WMA link:https://reference.wolfram.com/language/ref/DiamondMatrix.html
- - 'DiamondMatrix[$s]'
+
- 'DiamondMatrix[$s$]'
- Gives a diamond shaped kernel of size 2 $s$ + 1.
@@ -127,7 +127,7 @@ class DiskMatrix(Builtin):
:WMA link:https://reference.wolfram.com/language/ref/DiskMatrix.html
- - 'DiskMatrix[$s]'
+
- 'DiskMatrix[$s$]'
- Gives a disk shaped kernel of size 2 $s$ + 1.
diff --git a/mathics/builtin/messages.py b/mathics/builtin/messages.py
index d6ae30645..3c4d44a14 100644
--- a/mathics/builtin/messages.py
+++ b/mathics/builtin/messages.py
@@ -2,7 +2,6 @@
Message-related functions.
"""
-
import typing
from typing import Any
@@ -17,11 +16,11 @@
class Aborted(Predefined):
- """
+ r"""
:WMA link:https://reference.wolfram.com/language/ref/Aborted.html
- - '$Aborted'
+
- '\$Aborted'
- is returned by a calculation that has been aborted.
"""
@@ -125,10 +124,10 @@ def get_msg_list(exprs):
class Failed(Predefined):
- """
- :WMA link:https://reference.wolfram.com/language/ref/$Failed.html
+ r"""
+ :WMA link:https://reference.wolfram.com/language/ref/\$Failed.html
- - '$Failed'
+
- '\$Failed'
- is returned by some functions in the event of an error.
"""
diff --git a/mathics/builtin/numbers/algebra.py b/mathics/builtin/numbers/algebra.py
index 3380a4ce2..d3f186db3 100644
--- a/mathics/builtin/numbers/algebra.py
+++ b/mathics/builtin/numbers/algebra.py
@@ -1525,7 +1525,7 @@ class Simplify(Builtin):
simplifies $expr$.
'Simplify[$expr$, $assump$]'
- simplifies $expr$ assuming $assump$ instead of $Assumptions$.
+ simplifies $expr$ assuming $assump$ instead of '\$Assumptions'.
>> Simplify[2*Sin[x]^2 + 2*Cos[x]^2]
@@ -1535,23 +1535,23 @@ class Simplify(Builtin):
>> Simplify[f[x]]
= f[x]
- Simplify over conditional expressions uses $\$Assumptions$, or $assump$
+ Simplify over conditional expressions uses '\$Assumptions', or $assump$
to evaluate the condition:
>> $Assumptions={a <= 0};
>> Simplify[ConditionalExpression[1, a > 0]]
= Undefined
- The $assump$ option override $\$Assumption$:
+ The $assump$ option override '\$Assumption':
>> Simplify[ConditionalExpression[1, a > 0] ConditionalExpression[1, b > 0], { b > 0 }]
= ConditionalExpression[1, a > 0]
- On the other hand, $Assumptions$ option does not override $\$Assumption$, but add to them:
+ On the other hand, 'Assumptions' option does not override '\$Assumptions', but add to them:
>> Simplify[ConditionalExpression[1, a > 0] ConditionalExpression[1, b > 0], Assumptions -> { b > 0 }]
= ConditionalExpression[1, a > 0]
- Passing both options overwrites $Assumptions with the union of $assump$ the option
+ Passing both options overwrites '\$Assumptions' with the union of $assump$ the option
>> Simplify[ConditionalExpression[1, a > 0] ConditionalExpression[1, b > 0], {a>0},Assumptions -> { b > 0 }]
= 1
>> $Assumptions={};
- The option $ComplexityFunction$ allows to control the way in which the \
+ The option 'ComplexityFunction' allows to control the way in which the \
evaluator decides if one expression is simpler than another. For example, \
by default, 'Simplify' tries to avoid expressions involving numbers with many digits:
>> Simplify[20 Log[2]]
diff --git a/mathics/builtin/numbers/constants.py b/mathics/builtin/numbers/constants.py
index b2caf6162..b0c54dad3 100644
--- a/mathics/builtin/numbers/constants.py
+++ b/mathics/builtin/numbers/constants.py
@@ -595,19 +595,19 @@ class Overflow(Builtin):
class MaxMachineNumber(Predefined):
- """
+ r"""
Largest normalizable machine number (
:WMA:
- https://reference.wolfram.com/language/ref/$MaxMachineNumber.html
+ https://reference.wolfram.com/language/ref/\$MaxMachineNumber.html
)
- - '$MaxMachineNumber'
+
- '\$MaxMachineNumber'
- Represents the largest positive number that can be represented \
as a normalized machine number in the system.
- The product of '$MaxMachineNumber' and '$MinMachineNumber' is a constant:
+ The product of '\$MaxMachineNumber' and '\$MinMachineNumber' is a constant:
>> $MaxMachineNumber * $MinMachineNumber
= 4.
@@ -621,14 +621,14 @@ def evaluate(self, evaluation: Evaluation) -> MachineReal:
class MinMachineNumber(Predefined):
- """
+ r"""
Smallest normalizable machine number (
:WMA:
- https://reference.wolfram.com/language/ref/$MinMachineNumber.html
+ https://reference.wolfram.com/language/ref/\$MinMachineNumber.html
)
- - '$MinMachineNumber'
+
- '\$MinMachineNumber'
- Represents the smallest positive number that can be represented \
as a normalized machine number in the system.
diff --git a/mathics/builtin/numbers/numbertheory.py b/mathics/builtin/numbers/numbertheory.py
index 7259e9925..491862602 100644
--- a/mathics/builtin/numbers/numbertheory.py
+++ b/mathics/builtin/numbers/numbertheory.py
@@ -88,7 +88,7 @@ class DivisorSigma(SympyFunction):
- 'DivisorSigma[$k$, $n$]'
-
- returns $\sigma_k$($n$)
+
- returns $\sigma_k(n)$
For reference, let us first get the integer divisors of 20:
@@ -1001,7 +1001,7 @@ class RandomPrime(Builtin):
:Prime numbers:https://reference.wolfram.com/language/ref/RandomPrime.html
- - 'RandomPrime[{$imin$, $imax}]'
+
- 'RandomPrime[{$imin$, $imax$}]'
- gives a random prime between $imin$ and $imax$.
- 'RandomPrime[$imax$]'
diff --git a/mathics/builtin/procedural.py b/mathics/builtin/procedural.py
index 6544cf401..ee312eef3 100644
--- a/mathics/builtin/procedural.py
+++ b/mathics/builtin/procedural.py
@@ -41,13 +41,13 @@
class Abort(Builtin):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/Abort.html
- 'Abort[]'
-
- aborts an evaluation completely and returns '$Aborted'.
+
- aborts an evaluation completely and returns '\$Aborted'.
>> Print["a"]; Abort[]; Print["b"]
@@ -416,12 +416,12 @@ def eval_with_false_and_other(self, condition, t, f, u, evaluation):
class Interrupt(Builtin):
- """
+ r"""
:WMA link:https://reference.wolfram.com/language/ref/Interrupt.html
- 'Interrupt[]'
-
- Interrupt an evaluation and returns '$Aborted'.
+
- Interrupt an evaluation and returns '\$Aborted'.
>> Print["a"]; Interrupt[]; Print["b"]
diff --git a/mathics/builtin/quantum_mechanics/angular.py b/mathics/builtin/quantum_mechanics/angular.py
index cad013268..9a92c2b37 100644
--- a/mathics/builtin/quantum_mechanics/angular.py
+++ b/mathics/builtin/quantum_mechanics/angular.py
@@ -40,8 +40,8 @@ class ClebschGordan(SympyFunction):
- 'ClebschGordan[{$j1$, $m1$}, {$j2$, $m2$}, {$j$ $m$}]'
-
- returns the Clebsch-Gordan coefficient for the decomposition of |$j$,$m$> \
- in terms of |$j1$, $m$>, |$j2$, $m2$>.
+
- returns the Clebsch-Gordan coefficient for the decomposition of $|j, m\rangle$ \
+ in terms of $|j1, m\rangle$, $|j2, m2\rangle$.
>> ClebschGordan[{3 / 2, 3 / 2}, {1 / 2, -1 / 2}, {1, 1}]
@@ -143,7 +143,7 @@ class SixJSymbol(SympyFunction):
https://reference.wolfram.com/language/ref/SixJSymbol.html)
- - 'SixJSymbol[{$j1, $j2$, $j3$}, {$j4$, $j5$, $j6$}]'
+
- 'SixJSymbol[{$j1$, $j2$, $j3$}, {$j4$, $j5$, $j6$}]'
- returns the values of the Wigner 6-$j$ symbol.
diff --git a/mathics/builtin/scoping.py b/mathics/builtin/scoping.py
index 56bf89039..8243a9af5 100644
--- a/mathics/builtin/scoping.py
+++ b/mathics/builtin/scoping.py
@@ -112,7 +112,7 @@ class Begin(Builtin):
class BeginPackage(Builtin):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/BeginPackage.html
@@ -123,7 +123,7 @@ class BeginPackage(Builtin):
The $context$ argument must be a valid context name. 'BeginPackage' changes \
- the values of '$Context' and '$ContextPath', setting the current context to $context$.
+ the values of '\$Context' and '\$ContextPath', setting the current context to $context$.
## >> BeginPackage["test`"]
## = test`
@@ -269,12 +269,12 @@ def eval_with_string(self, string, evaluation: Evaluation) -> ListExpression:
class ContextPath_(Predefined):
- """
+ r"""
:WMA link
- :https://reference.wolfram.com/language/ref/$ContextPath.html
+ :https://reference.wolfram.com/language/ref/\$ContextPath.html
- - '$ContextPath'
+
- '\$ContextPath'
- is the search path for contexts.
@@ -299,14 +299,14 @@ class ContextPath_(Predefined):
class ContextPathStack(Builtin):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/ContextPathStack.html
- - 'System`Private`$ContextPathStack'
-
- is an internal variable tracking the values of '$ContextPath' \
+
- 'System`Private`\$ContextPathStack'
+
- is an internal variable tracking the values of '\$ContextPath' \
saved by 'Begin' and 'BeginPackage'.
"""
@@ -321,13 +321,13 @@ class ContextPathStack(Builtin):
class ContextStack(Builtin):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/ContextStack.html
- - 'System`Private`$ContextStack'
-
- is an internal variable tracking the values of '$Context'
+
- 'System`Private`\$ContextStack'
+
- is an internal variable tracking the values of '\$Context'
saved by 'Begin' and 'BeginPackage'.
"""
@@ -372,7 +372,7 @@ class End(Builtin):
class EndPackage(Builtin):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/EndPackage.html
@@ -382,8 +382,8 @@ class EndPackage(Builtin):
marks the end of a package, undoing a previous 'BeginPackage'.
- After 'EndPackage', the values of '$Context' and '$ContextPath' at the \
- time of the 'BeginPackage' call are restored, with the new package\'s context prepended to $ContextPath.
+ After 'EndPackage', the values of '\$Context' and '\$ContextPath' at the \
+ time of the 'BeginPackage' call are restored, with the new package\'s context prepended to '\$ContextPath'.
"""
messages = {
@@ -408,7 +408,7 @@ class EndPackage(Builtin):
class Module(Builtin):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/Module.html
@@ -416,8 +416,8 @@ class Module(Builtin):
- 'Module[{$vars$}, $expr$]'
- localizes variables by giving them a temporary name of the form \
- 'name$number', where number is the current value of '$ModuleNumber'. \
- Each time a module is evaluated, '$ModuleNumber' is incremented.
+ 'name\$number', where number is the current value of '\$ModuleNumber'. \
+ Each time a module is evaluated, '\$ModuleNumber' is incremented.
## FIXME: fix and go over
@@ -483,30 +483,30 @@ def eval(self, vars, expr, evaluation: Evaluation):
class ModuleNumber_(Predefined):
- """
+ r"""
:WMA link:
- https://reference.wolfram.com/language/ref/$ModuleNumber.html
+ https://reference.wolfram.com/language/ref/\$ModuleNumber.html
- - '$ModuleNumber'
+
- '\$ModuleNumber'
- is the current "serial number" to be used for local module variables.
- - '$ModuleNumber' is incremented every time 'Module' or 'Unique' is called.
-
- a Mathics session starts with '$ModuleNumber' set to 1.
-
- You can reset $ModuleNumber to a positive machine integer, but if \
+
- '\$ModuleNumber' is incremented every time 'Module' or 'Unique' is called.
+
- a Mathics session starts with '\$ModuleNumber' set to 1.
+
- You can reset '\$ModuleNumber' to a positive machine integer, but if \
you do so, naming conflicts may lead to inefficiencies.
## Fixme: go over and adjuset
- ## Each use of 'Module' increments '$ModuleNumber':
+ ## Each use of 'Module' increments '\$ModuleNumber':
## >> {$ModuleNumber, Module[{y}, y], $ModuleNumber}
## = {..., ...}
## FIXME and go over
- ## You can reset $ModuleNumber:
+ ## You can reset '\$ModuleNumber':
## >> $ModuleNumber = 17; {Module[{x}, x], $ModuleNumber}
## = {x$17, 18}
##
@@ -529,17 +529,17 @@ class ModuleNumber_(Predefined):
class Unique(Predefined):
- """
+ r"""
:WMA link:
https://reference.wolfram.com/language/ref/Unique.html
- 'Unique[]'
-
- generates a new symbol and gives a name of the form '$number'.
+
- generates a new symbol and gives a name of the form '\$number'.
- 'Unique[x]'
-
- generates a new symbol and gives a name of the form 'x$number'.
+
- generates a new symbol and gives a name of the form 'x\$number'.
- 'Unique[{x, y, ...}]'
- generates a list of new symbols.
@@ -557,7 +557,7 @@ class Unique(Predefined):
= x...
## FIXME: include the rest of these in test/builtin/test-unique.py
- ## Each use of Unique[symbol] increments $ModuleNumber:
+ ## Each use of Unique[symbol] increments '\$ModuleNumber':
## >> {$ModuleNumber, Unique[x], $ModuleNumber}
## = ...
diff --git a/mathics/builtin/string/regexp.py b/mathics/builtin/string/regexp.py
index da8d55ff7..02db0ca62 100644
--- a/mathics/builtin/string/regexp.py
+++ b/mathics/builtin/string/regexp.py
@@ -15,7 +15,7 @@ class RegularExpression(Builtin):
- 'RegularExpression["regex"]'
-
- represents the regex specified by the string $"regex"$.
+
- represents the regex specified by the string "$regex$".
>> StringSplit["1.23, 4.56 7.89", RegularExpression["(\\s|,)+"]]
diff --git a/mathics/builtin/system.py b/mathics/builtin/system.py
index 8b26cc7d0..39003691d 100644
--- a/mathics/builtin/system.py
+++ b/mathics/builtin/system.py
@@ -76,15 +76,14 @@ class Breakpoint(Builtin):
def eval(self, evaluation: Evaluation):
"Breakpoint[]"
-
breakpoint()
class CommandLine(Predefined):
"""
- :WMA link:https://reference.wolfram.com/language/ref/$CommandLine.html
+ :WMA link:https://reference.wolfram.com/language/ref/\\$CommandLine.html
- - '$CommandLine'
+
- '\\$CommandLine'
- is a list of strings passed on the command line to launch the Mathics3 session.
@@ -217,10 +216,10 @@ def eval(self, var, evaluation: Evaluation):
class Machine(Predefined):
"""
- :WMA link:https://reference.wolfram.com/language/ref/$Machine.html
+ :WMA link:https://reference.wolfram.com/language/ref/\\$Machine.html
- - '$Machine'
+
- '\\$Machine'
- returns a string describing the type of computer system on which the \
Mathics3 is being run.
@@ -241,7 +240,7 @@ class MachineName(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/MachineName.html
- - '$MachineName'
+
- '\\$MachineName'
- is a string that gives the assigned name of the computer on which Mathics3 \
is being run, if such a name is defined.
@@ -287,7 +286,7 @@ class MaxLengthIntStringConversion(Predefined):
string value is too large, then the middle of the integer contains \
an indication of the number of digits elided inside << >>.
- If '$MaxLengthIntStringConversion' is set to 0, there is no \
+ If '\\$MaxLengthIntStringConversion' is set to 0, there is no \
bound. Aside from 0, 640 is the smallest value allowed.
The initial value can be set via environment variable \
@@ -303,7 +302,7 @@ class MaxLengthIntStringConversion(Predefined):
the number of digits allows when converting a large integer into \
a string.
- Show the default value of '$MaxLengthIntStringConversion':
+ Show the default value of '\\$MaxLengthIntStringConversion':
>> $MaxLengthIntStringConversion
= ...
@@ -311,14 +310,14 @@ class MaxLengthIntStringConversion(Predefined):
>> 500! //ToString//StringLength
= ...
- We first set '$MaxLengthIntStringConversion' to the smallest value allowed, \
+ We first set '\\$MaxLengthIntStringConversion' to the smallest value allowed, \
so that we can see the truncation of digits in the middle:
>> $MaxLengthIntStringConversion = 640
## Pyston 2.3.5 returns 0 while CPython returns 640
## Therefore output testing below is generic.
= ...
- Note that setting '$MaxLengthIntStringConversion' has an effect only on Python 3.11 and later;
+ Note that setting '\\$MaxLengthIntStringConversion' has an effect only on Python 3.11 and later;
Pyston 2.x however ignores this.
Now when we print the string value of 500! and Pyston 2.x is not used, \
@@ -397,7 +396,7 @@ class Packages(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/Packages.html
- - '$Packages'
+
- '\\$Packages'
- returns a list of the contexts corresponding to all packages which have \
been loaded into Mathics.
@@ -418,7 +417,7 @@ class ParentProcessID(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/$ParentProcessID.html
- - '$ParentProcesID'
+
- '\$ParentProcesID'
- gives the ID assigned to the process which invokes Mathics3 by the operating \
system under which it is run.
@@ -440,7 +439,7 @@ class ProcessID(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/ProcessID.html
- - '$ProcessID'
+
- '\$ProcessID'
- gives the ID assigned to the Mathics3 process by the operating system under \
which it is run.
@@ -463,7 +462,7 @@ class ProcessorType(Predefined):
https://reference.wolfram.com/language/ref/ProcessorType.html
- - '$ProcessorType'
+
- '\\$ProcessorType'
- gives a string giving the architecture of the processor on which \
Mathics3 is being run.
@@ -487,7 +486,7 @@ class PythonImplementation(Predefined):
## :PythonImplementation native symbol:
- - '$PythonImplementation'
+
- '\$PythonImplementation'
- gives a string indication the Python implementation used to run Mathics3.
@@ -532,7 +531,7 @@ class ScriptCommandLine(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/ScriptCommandLine.html
- - '$ScriptCommandLine'
+
- '\\$ScriptCommandLine'
- is a list of string arguments when running the kernel is script mode.
@@ -559,10 +558,10 @@ class SetEnvironment(Builtin):
:WMA link:https://reference.wolfram.com/language/ref/SetEnvironment.html
- - 'SetEnvironment["$var$" -> $value"]'
+
- 'SetEnvironment["$var$" -> "$value$"]'
- sets the value of an operating system environment variable.
-
- 'SetEnvironment[{"$var$" -> $value", ...}]'
+
- 'SetEnvironment[{"$var$" -> "$value$", ...}]'
- sets more than one environment variable.
@@ -682,7 +681,7 @@ class SystemID(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/SystemID.html
- - '$SystemID'
+
- '\$SystemID'
- is a short string that identifies the type of computer system on which the \Mathics is being run.
@@ -702,7 +701,7 @@ class SystemWordLength(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/SystemWordLength.html
- - '$SystemWordLength'
+
- '\$SystemWordLength'
- gives the effective number of bits in raw machine words on the computer \
system where Mathics3 is running.
@@ -729,7 +728,7 @@ class UserName(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/UserName.html
- - $UserName
+
- \$UserName
- returns the login name, according to the operative system, of the user that started the current
\Mathics session.
@@ -776,7 +775,7 @@ class VersionNumber(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/VersionNumber.html
- - '$VersionNumber'
+
- '\$VersionNumber'
- is a real number which gives the current Wolfram Language version that \Mathics tries to be compatible with.
@@ -801,7 +800,7 @@ class SystemMemory(Predefined):
:WMA link:https://reference.wolfram.com/language/ref/SystemMemory.html
- - '$SystemMemory'
+
- '\\$SystemMemory'
- Returns the total amount of physical memory.
@@ -828,7 +827,7 @@ class MemoryAvailable(Builtin):
>> MemoryAvailable[]
= ...
- The relationship between $SystemMemory, MemoryAvailable, and MemoryInUse:
+ The relationship between \\$SystemMemory, MemoryAvailable, and MemoryInUse:
>> $SystemMemory > MemoryAvailable[] > MemoryInUse[]
= True
"""
diff --git a/mathics/builtin/testing_expressions/equality_inequality.py b/mathics/builtin/testing_expressions/equality_inequality.py
index 86a253f5c..0884df8e1 100644
--- a/mathics/builtin/testing_expressions/equality_inequality.py
+++ b/mathics/builtin/testing_expressions/equality_inequality.py
@@ -766,7 +766,7 @@ class Min(_MinMax):
class SameQ(_ComparisonOperator):
- """
+ r"""
:WMA link:https://reference.wolfram.com/language/ref/SameQ.html
@@ -809,7 +809,7 @@ class SameQ(_ComparisonOperator):
$0.222`3$ is not equivalent to $0.2222`3$:
>> .2222222`6 === .222`3
= False
- 15.9546 is the value of '$MaxPrecision'
+ 15.9546 is the value of '\$MaxPrecision'
"""
grouping = "None" # Indeterminate grouping: Neither left nor right
diff --git a/mathics/builtin/trace.py b/mathics/builtin/trace.py
index 3529ead48..7c5bed833 100644
--- a/mathics/builtin/trace.py
+++ b/mathics/builtin/trace.py
@@ -101,7 +101,7 @@ def eval(self, evaluation: Evaluation):
class PrintTrace(_TraceBase):
- """
+ r"""
## :trace native symbol:
@@ -120,7 +120,7 @@ class PrintTrace(_TraceBase):
Note that in a browser the information only appears in a console.
- Note: before '$TraceBuiltins' is set to 'True', 'PrintTrace[]' will print an empty
+ Note: before '\$TraceBuiltins' is set to 'True', 'PrintTrace[]' will print an empty
list.
>> PrintTrace[] (* See console log *)
@@ -277,11 +277,11 @@ def eval(self, expr, evaluation, options={}):
# The convention is to use the name of the variable without the "$" as
# the class name, but it is already taken by the builtin `TraceBuiltins`
class TraceBuiltinsVariable(Builtin):
- """
+ r"""
## :trace native symbol:
- - '$TraceBuiltins'
+
- '\$TraceBuiltins'
- A Boolean Built-in variable when True collects function evaluation statistics.
@@ -310,7 +310,7 @@ class TraceBuiltinsVariable(Builtin):
To clear statistics collected use 'ClearTrace[]':
X> ClearTrace[]
- '$TraceBuiltins' cannot be set to a non-boolean value.
+ '\$TraceBuiltins' cannot be set to a non-boolean value.
>> $TraceBuiltins = x
: x should be True or False.
= x
@@ -404,11 +404,11 @@ def eval(self, expr, evaluation: Evaluation, options: dict):
class TraceEvaluationVariable(Builtin):
- """
+ r"""
## :trace native symbol:
- - '$TraceEvaluation'
+
- '\$TraceEvaluation'
- A Boolean variable which when set True traces Expression evaluation calls and returns.
@@ -429,7 +429,7 @@ class TraceEvaluationVariable(Builtin):
>> a + a
= 2 a
- '$TraceEvaluation' cannot be set to a non-boolean value.
+ '\$TraceEvaluation' cannot be set to a non-boolean value.
>> $TraceEvaluation = x
: x should be True or False.
= x
diff --git a/mathics/builtin/vectors/math_ops.py b/mathics/builtin/vectors/math_ops.py
index 19f373740..347a79c30 100644
--- a/mathics/builtin/vectors/math_ops.py
+++ b/mathics/builtin/vectors/math_ops.py
@@ -94,7 +94,7 @@ class Curl(SympyFunction):
- 'Curl[{$f1$, $f2$}, {$x1$, $x2$}]'
- returns the curl $df2$/$dx1$ - $df1$/$dx2$
-
- 'Curl[{$f1$, $f2$, $f3} {$x1$, $x2$, $x3}]'
+
- 'Curl[{$f1$, $f2$, $f3$} {$x1$, $x2$, $x3$}]'
- returns the curl ($df3$/$dx2$ - $df2$/$dx3$, $dx3$/$df$3 - $df3$/$dx1$, $df2$/$df1$ - $df1$/$dx2$)
diff --git a/mathics/doc/doc_entries.py b/mathics/doc/doc_entries.py
index 201d4ae19..a7600338b 100644
--- a/mathics/doc/doc_entries.py
+++ b/mathics/doc/doc_entries.py
@@ -10,7 +10,7 @@
import logging
import re
from os import getenv
-from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Sequence
+from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Sequence, Tuple
from mathics.core.evaluation import Message, Print, _Out
@@ -160,9 +160,11 @@ def filter_comments(doc: str) -> str:
POST_SUBSTITUTION_TAG = "_POST_SUBSTITUTION%d_"
-def pre_sub(regexp, text: str, repl_func: Callable):
+def pre_sub(
+ regexp, text: str, repl_func: Callable, prev_subst: Tuple = tuple()
+) -> Tuple[str, Tuple]:
"""apply substitutions previous to parse the text"""
- post_substitutions: List[str] = []
+ post_substitutions: List[str] = list(prev_subst)
def repl_pre(match):
repl = repl_func(match)
@@ -172,10 +174,10 @@ def repl_pre(match):
text = regexp.sub(repl_pre, text)
- return text, post_substitutions
+ return text, tuple(post_substitutions)
-def post_sub(text: str, post_substitutions) -> str:
+def post_sub(text: str, post_substitutions: Tuple) -> str:
"""apply substitutions after parsing the doctests."""
for index, sub in enumerate(post_substitutions):
text = text.replace(POST_SUBSTITUTION_TAG % index, sub)
diff --git a/mathics/doc/documentation/1-Manual.mdoc b/mathics/doc/documentation/1-Manual.mdoc
index 7c5f27ffd..442edee33 100644
--- a/mathics/doc/documentation/1-Manual.mdoc
+++ b/mathics/doc/documentation/1-Manual.mdoc
@@ -746,8 +746,8 @@ However, sometimes "local" variables are needed in order not to disturb the glob
- 'Module[{$vars$}, $expr$]'
- localizes variables by giving them a temporary name of the form
- 'name$number', where number is the current value of '$ModuleNumber'. Each time a module
- is evaluated, '$ModuleNumber' is incremented.
+ 'name\$number', where number is the current value of '\$ModuleNumber'. Each time a module
+ is evaluated, '\$ModuleNumber' is incremented.
- 'Block[{$vars$}, $expr$]'
- temporarily stores the definitions of certain variables, evaluates
diff --git a/mathics/doc/latex_doc.py b/mathics/doc/latex_doc.py
index 32c3cc090..0fecd8e13 100644
--- a/mathics/doc/latex_doc.py
+++ b/mathics/doc/latex_doc.py
@@ -58,6 +58,12 @@
LATEX_CONSOLE_RE = re.compile(r"\\console\{(.*?)\}")
LATEX_INLINE_END_RE = re.compile(r"(?s)(?P\\lstinline'[^']*?'\}?[.,;:])")
+LATEX_DISPLAY_EQUATION_RE = re.compile(r"(?m)(?.*?)\}\{(?P.*?)\}")
+LATEX_URL_RE = re.compile(r"(?s)\\url\{(?P.*?)\}")
+
+
LATEX_TEXT_RE = re.compile(
r"(?s)\\text\{([^{}]*?(?:[^{}]*?\{[^{}]*?(?:[^{}]*?\{[^{}]*?\}[^{}]*?)*?"
r"[^{}]*?\}[^{}]*?)*?[^{}]*?)\}"
@@ -69,6 +75,7 @@
LATEX_TESTOUT_DELIM_RE = re.compile(r", ")
+MATHICS_VARIABLE_NAME = re.compile(r"[\$\`A-Za-z0-9]*")
# The goal of the following pattern is to enclose the numbers included in
# expressions produced by tests between ```\allowbreak{}```. The pattern matches
# with negative numbers or positive numbers preceded by a space character.
@@ -91,7 +98,56 @@ def escape_latex_code(text) -> str:
def escape_latex(text):
- """Escape documentation text"""
+ """
+ Escape documentation text.
+
+ A block of text in the docstring documentation system
+ is a mixture of XML, LaTeX, and *literal* Python and
+ WL code, in a mixture that is not fully compatible
+ with Markdown or RST text, so we are not able to use
+ an standard parser.
+
+ To convert this into pure LaTeX code, this function
+ collects certain parts like LaTeX equations or verbatim
+ WL code using Python regular expressions. These blocks
+ are processed and stored, and replaced in the original
+ text by numerated placeholders.
+
+ The remaining text is then parsed to replace or escape
+ special characters, and some special markers.
+
+ Finally, the placeholders are replaced by the processed
+ blocks, to get a valid LaTeX code.
+
+ Notice that to use the `$` character as a character and
+ not as an equation marker, it should be escaped.
+
+ An special case is the one of variable names. In that case,
+ that consists of numbers, alphabetic characters, and
+ the special characters '`' and '$' is treated different,
+ because they come from Symbol names and not from docstrings.
+
+ For general, multiline code, the processing is done in the
+ following order:
+
+ * First the verbatim Python code is extracted.
+ * Then, URLs are and references are collected.
+ * After that, anything sorrounded by '$' or '$$'
+ is processed.
+ * Then, some LaTeX special characters, like brackets,
+ are escaped.
+ * After that, the remaining WL code and XML code is translated
+ to LaTeX.
+ * Finally, all the placeholders are replaced to the postprocessed
+ form.
+
+ """
+
+ # Single line, no spaces, maybe a Symbol name
+ if "\n" not in text and " " not in text:
+ if MATHICS_VARIABLE_NAME.match(text):
+ text = text.replace("$", r"\$")
+ return text
def repl_python(match):
return (
@@ -101,12 +157,84 @@ def repl_python(match):
% match.group(1).strip()
)
+ def repl_eq(match):
+ return "$" + match.group(1) + "$"
+
+ # Protect Python code from further replacements.
text, post_substitutions = pre_sub(PYTHON_RE, text, repl_python)
+ # Process hyperrefs
+ def repl_quotation(match):
+ return r"``%s''" % match.group(1)
+
+ def ensure_sharp_escape_in_url(content) -> str:
+ content = content.replace(" ", "").replace("\n", "")
+ return content.replace("#", r"\#").replace(r"\\#", r"\#")
+
+ def repl_hypertext(match) -> str:
+ tag = match.group("tag")
+ content = ensure_sharp_escape_in_url(match.group("content"))
+ #
+ # Sometimes it happens that the URL does not
+ # fit in 80 characters. Then, to avoid that
+ # flake8 complains, and also to have a
+ # nice and readable ASCII representation,
+ # we would like to split the URL in several,
+ # lines, having indentation spaces.
+ #
+ # The following line removes these extra
+ # characters, which would spoil the URL,
+ # producing a single line, space-free string.
+ #
+ if tag == "em":
+ return r"\emph{%s}" % content
+ elif tag == "url":
+ text = match.group("text")
+ if text is None:
+ return "\\url{%s}" % content
+ else:
+ # If we have "/doc" as the beginning the URL link
+ # then is is a link to a section
+ # in this manual, so use "\ref" rather than "\href'.
+ if content.find("/doc/") == 0:
+ slug = "/".join(content.split("/")[2:]).rstrip("/")
+ return "%s \\ref{%s}" % (text, latex_label_safe(slug))
+ # slug = "/".join(content.split("/")[2:]).rstrip("/")
+ # return "%s of section~\\ref{%s}" % (text, latex_label_safe(slug))
+ else:
+ return "\\href{%s}{%s}" % (content, text)
+ return "\\href{%s}{%s}" % (content, text)
+
+ def repl_href(match) -> str:
+ content = ensure_sharp_escape_in_url(match.group("content"))
+ return r"\href{%s}{%s}" % (content, match.group("text"))
+
+ def repl_url(match) -> str:
+ content = ensure_sharp_escape_in_url(match.group("content"))
+ return r"\url{%s}" % (content,)
+
+ text, post_substitutions = pre_sub(QUOTATIONS_RE, text, repl_quotation)
+ text, post_substitutions = pre_sub(
+ HYPERTEXT_RE, text, repl_hypertext, tuple(post_substitutions)
+ )
+ text, post_substitutions = pre_sub(
+ LATEX_HREF_RE, text, repl_href, tuple(post_substitutions)
+ )
+ text, post_substitutions = pre_sub(
+ LATEX_URL_RE, text, repl_url, tuple(post_substitutions)
+ )
+
+ # Protect LaTeX equations from further replacements.
+ text, post_substitutions = pre_sub(
+ LATEX_DISPLAY_EQUATION_RE, text, repl_eq, tuple(post_substitutions)
+ )
+ text, post_substitutions = pre_sub(
+ LATEX_INLINE_EQUATION_RE, text, repl_eq, tuple(post_substitutions)
+ )
+
text = replace_all(
text,
[
- ("\\", "\\\\"),
("{", "\\{"),
("}", "\\}"),
("~", "\\~{ }"),
@@ -119,7 +247,7 @@ def repl_python(match):
def repl(match):
text = match.group(1)
if text:
- text = replace_all(text, [("\\'", "'"), ("^", "\\^")])
+ text = replace_all(text, [(r"\'", "'"), ("^", r"\^")])
escape_char = get_latex_escape_char(text)
text = LATEX_RE.sub(
lambda m: "%s%s\\codevar{\\textit{%s}}%s\\lstinline%s"
@@ -137,17 +265,16 @@ def repl(match):
text = MATHICS_RE.sub(repl, text)
- text = LATEX_RE.sub(
- lambda m: "%s\\textit{%s}%s" % (m.group(1), m.group(2), m.group(3)), text
- )
-
text = text.replace("\\\\'", "'")
def repl_dl(match):
text = match.group(1)
- text = DL_ITEM_RE.sub(
- lambda m: "\\%(tag)s{%(content)s}\n" % m.groupdict(), text
- )
+
+ def repl_dd_dt(match):
+ match_dict = match.groupdict()
+ return "\\%(tag)s{%(content)s}\n" % match_dict
+
+ text = DL_ITEM_RE.sub(repl_dd_dt, text)
return "\\begin{definitions}%s\\end{definitions}" % text
text = DL_RE.sub(repl_dl, text)
@@ -161,36 +288,6 @@ def repl_list(match):
text = LIST_RE.sub(repl_list, text)
- # FIXME: get this from MathicsScanner
- text = replace_all(
- text,
- [
- ("$", r"\$"),
- ("\00f1", r"\~n"),
- ("\u00e7", r"\c{c}"),
- ("\u2216", r"\\"),
- ("\u00e9", r"\'e"),
- ("\u00ea", r"\^e"),
- ("\u03b3", r"$\gamma$"),
- ("\u03b8", r"$\theta$"),
- ("\u03bc", r"$\mu$"),
- ("\u03c0", r"$\pi$"),
- ("\u03d5", r"$\phi$"),
- ("\u2107", r"$\mathrm{e}$"),
- ("\u222b", r"\int"),
- ("\u2243", r"$\simeq$"),
- ("\u2026", r"$\dots$"),
- ("\u2260", r"$\ne$"),
- ("\u2264", r"$\le$"),
- ("\u2265", r"$\ge$"),
- ("\u22bb", r"$\oplus$"), # The WL veebar-looking symbol isn't in AMSLaTeX
- ("\u22bc", r"$\barwedge$"),
- ("\u22bd", r"$\veebar$"),
- ("\u21d2", r"$\Rightarrow$"),
- ("\uf74c", r"d"),
- ],
- )
-
def repl_char(match):
char = match.group(1)
return {
@@ -227,47 +324,6 @@ def repl_ref(match):
text = REF_RE.sub(repl_ref, text)
- def repl_quotation(match):
- return r"``%s''" % match.group(1)
-
- def repl_hypertext(match) -> str:
- tag = match.group("tag")
- content = match.group("content")
- #
- # Sometimes it happens that the URL does not
- # fit in 80 characters. Then, to avoid that
- # flake8 complains, and also to have a
- # nice and readable ASCII representation,
- # we would like to split the URL in several,
- # lines, having indentation spaces.
- #
- # The following line removes these extra
- # characters, which would spoil the URL,
- # producing a single line, space-free string.
- #
- content = content.replace(" ", "").replace("\n", "")
- if tag == "em":
- return r"\emph{%s}" % content
- elif tag == "url":
- text = match.group("text")
- if text is None:
- return "\\url{%s}" % content
- else:
- # If we have "/doc" as the beginning the URL link
- # then is is a link to a section
- # in this manual, so use "\ref" rather than "\href'.
- if content.find("/doc/") == 0:
- slug = "/".join(content.split("/")[2:]).rstrip("/")
- return "%s \\ref{%s}" % (text, latex_label_safe(slug))
- # slug = "/".join(content.split("/")[2:]).rstrip("/")
- # return "%s of section~\\ref{%s}" % (text, latex_label_safe(slug))
- else:
- return "\\href{%s}{%s}" % (content, text)
- return "\\href{%s}{%s}" % (content, text)
-
- text = QUOTATIONS_RE.sub(repl_quotation, text)
- text = HYPERTEXT_RE.sub(repl_hypertext, text)
-
def repl_console(match):
tag = match.group("tag")
content = match.group("content")
@@ -303,8 +359,7 @@ def repl_subsection(match):
text = SUBSECTION_END_RE.sub("", text)
for key, (xml, tex) in SPECIAL_COMMANDS.items():
- # "\" has been escaped already => 2 \
- text = text.replace("\\\\" + key, tex)
+ text = text.replace("\\" + key, tex)
text = post_sub(text, post_substitutions)
diff --git a/test/doc/test_latex.py b/test/doc/test_latex.py
index 9541922fc..d15df61e0 100644
--- a/test/doc/test_latex.py
+++ b/test/doc/test_latex.py
@@ -87,8 +87,8 @@ def test_load_latex_documentation():
r"\begin{testresult}o\end{testresult}\end{testcase}"
)
assert (
- doc_in_section.latex(doc_data)[:39]
- ).strip() == "Let's sketch the function\n\\begin{tests}"
+ doc_in_section.latex(doc_data)[:40]
+ ).strip() == "Let\\'s sketch the function\n\\begin{tests}"
assert (
first_section.latex(doc_data)[:30]
).strip() == "\\section{Curve Sketching}{}"