Mathematica Toolbox is a set of shortcodes for users who sometimes write about Mathematica programming. It is the only WordPress plugin that supports syntax highlighting for Wolfram Language, the language used in Mathematica.
Syntax highlighting and formatting
- Uses the same highlighting script that is used on Mathematica.StackExchange.com and on Wolfram Community.
- Preserves code indentation and prevents WordPress from inserting
<br>
and<p>
into code. - Replaces Wolfram Language character codes such as
\[Alpha]
,\[Gamma]
etc. with their corresponding characters.
The highlighting feature can be triggered in two ways. In the editor [wlcode]Wolfram Language code here[/wlcode]
can be used to place a code block directly into the text, however it is often desirable to put the code elsewhere and refer to it instead of putting it into the text itself. This is achieved by the shortcode [wlcode field="name"]
where name
refers to a custom post field that holds the code that should be inserted at that point. You may have to go to "screen options" at the top of the editor page to enable custom post fields before you can see the custom post field form.
To write code as a part of a sentence, that is, inline, you can use the shortcode [wlinline]code[/wlinline]
. This will wrap the code with the <code>
tag and thus (in many themes) distinguish the code visually.
Embed Wolfram technologies
- Easily embed CDFs on any post or page.
- Retrieve and display an image from a Wolfram Cloud API.
- Retrieve and display raw data from a Wolfram Cloud API.
- Display a link to the documentation of a Wolfram Language function.
The official plugin from Wolfram Research that embeds CDFs does not work since WordPress 4.0.1. The shortcode in this plugin takes exactly the same arguments, so the instructions for that plugin are still valid and migration is painless.
The shortcode is [WolframCDF source="" width="" height="" altimage="" altimagewidth="" altimageheight=""]
, and the parameters and the alternative image (that is shown to those that don't have the CDF player) can be retrieve from the export wizard in Mathematica. The CDF file and the image can be uploaded to WordPress' media library. source
and altimage
refer to the URLs of these two files.
The Wolfram Language functions CloudDeploy
and APIFunction
can be used to deploy so called instant APIs. The url to an instant API includes an ID number that identifies that particular API. [WolframCloudAPI id=""]
can be used to display the result of calling the API if it is an image, and [WolframCloudAPI id="" image="false"]
if it isn't. Any extra parameters that the API needs can also be passed along There are two working examples for this feature under FAQ.
The shortcode [wldoc]function[/wldoc]
generates a link to the online documentation page of function
.
Retrieve posts from Mathematica.StackExchange.com
The shortcode [mma_se_questions ids="11350;3345;3646"]
retrieves the questions with the given IDs. Note that the IDs are separated by semicolons. Answers can be retrieved similarly by [mma_se_answers ids="25616;259"]
. The display format in each case is an unordered list.
Retrieve profile information from Mathematica.StackExchange.com
The shortcode [mma_se_user user_id="731"]
displays a link to the Mathematica.StackExchange user profile of user 731. The link text is the user's name. [mma_se_user user_id="731" link="false"]
displays the name without turning it into a link.
The shortcode [mma_se_profile_box user_id="731"]
displays a box with basic facts about user 731. Please see the screenshots page for a better understanding of what the result is.
The shortcode [mma_se_user_questions user_id="731"]
and [mma_se_user_answers user_id="731"]
displays lists of questions and answers respectively written by user 731. This shortcode is a direct interface between WordPress and the Stack Exchange API: any parameter in the API can be added to the shortcode. For example [mma_se_user_questions user_id="731" pagesize="5" sort="votes"]
returns the five questions asked by user 731 that have the most votes. The full set of parameters is in the documentation for the Stack Exchange API.
Caching of results
Note that queries sent to the Stack Exchange API are cached in the background, so for example [mma_se_user user_id="731"]
will only look that user up once a week at most, because a week is the default expiration time of the cache. It's good to let the cache expire because sometimes users change their names. All mma_se_
shortcodes accept a parameter called expiration
that can be used to specify the expiration time in seconds.
Credits
The highlighter script is Google Code Prettify.
Patrick Scheibe wrote the Google Code Prettify extension for Mathematica. He also wrote this browser extension with capablities that inspired this plugin, documentation links and Mathematica glyph codes to glyphs conversion.
The CDF embedding Javascript script was written by Wolfram Research.
The WordPress Plugin Boilerplate was used in this project.
The banner at the top of this page was generated with code that's available in the Mathematica documentation under
ArrayPlot
.