Overview

Mathematica Toolbox is a set of shortcodes for WordPress relevant for Mathematica users. They can be used for such things as:

  • Including CDFs in WordPress posts or pages.
  • Posting properly formatted and highlighted snippets of Wolfram Language/Mathematica code.
  • Fetching results from APIs deployed to Wolfram Cloud and displaying them.
  • Fetching information from Mathematica.StackExchange and displaying it.

The box that gave the Mathematica Toolbox plugin its name is a meta box that appears right under a the post editor in the WordPress administration panel. The image below shows what it looks like. A second meta box provides additional functionality related to Mathematica StackExchange. By clicking on one of the buttons a placeholder shortcode corresponding to the selected function is inserted into the post. Filling out the parameters is usually very straightforward. If you don't get a shortcode to work you can find detailed explanations of the shortcodes further down on this page.

Screenshot of the plugin meta boxes in the WordPress administration panel. The buttons insert shortcode templates into the post. The boxes are helpful but not necessary for the shortcodes to work and can be hidden from the screen options menu.

Where to get help

If you encounter problems that you cannot solve with the information in this documentation please use the support forum for Mathematica Toolbox. If necessary you can also find my email in my Github profile.

Embedding CDFs

The first plugin to provide the ability to include CDFs in WordPress posts and pages was Wolfram CDF. Unfortunately it does not work anymore because it isn't being maintained and it broke as a result of updates that were part of WordPress 4.0.1. To make it easy for users to transition to Mathematica Toolbox it has kept the same shortcode. Uers who wish transition only have to uninstall the old plugin and install this one.

The placeholder shortcode is this:

[WolframCDF source="" width="320" height="415" altimage="" altimagewidth="" altimageheight=""]

Parameters

source
  • Required: Yes
  • Input type(s): url to CDF
  • Description: Mathematica Toolbox has whitelisted the .cdf extension so that CDFs can be uploaded just like regular media files. The file manager will tell you the URL to the CDF that you have uploaded.
width
  • Required: Yes
  • Input type(s): Integer
  • Description: The CDF's width in pixels.
height
  • Required: Yes
  • Input type(s): Integer
  • Description: The CDF's height in pixels.
altimage
  • Required: No
  • Input type(s): image url
  • Description: If the CDF player is not installed this image will be shown instead. If left blank a default image will be shown instead.
altimagewidth
  • Required: No
  • Input type(s): Integer
  • Description: The alternative image's height in pixels.
altimageheight
  • Required: No
  • Input type(s): Integer
  • Description: The alternative image's height in pixels.

Possible issues

  • The CDF player browser plugin relies on NPAPI to communicate with browsers, just like other popular plugins such as Flash. Some of the most popular browsers are currently phasing out their support for NPAPI. At the time of writing (June, 2016) Google Chrome does not support NPAPI. Opera dropped support in their May, 2016 release and Firefox intends to drop support by the end of 2016. Browsers without NPAPI support cannot be used to view CDFs.
  • Make sure that you have the latest version of the CDF player, otherwise CDFs may not show up in the browser.

Screenshot of the WordPress plugin directory. The entry for the plugin WolframCDF now points to Mathematica Toolbox.

Screenshot of what it can look like when a visitor does not have the CDF player installed. Using the CDF web deployment wizard in Mathematica is very advantageous because it will generate an image like the one above for your CDF, to be used as an alternative image, and tell you what the dimensions of the CDF are. This is all the information you need to fill out the shortcode parameters.

Interacting with Wolfram Cloud

As of Mathematica 10 it is possible to deploy so called instant APIs to the Wolfram Cloud using CloudDeploy and APIFunction. Mathematica Toolbox can fetch information from deployed APIs and display it in blog posts. The shortcode for doing so is

[WolframCloudAPI id="..."]

Parameters

Retrieves and displays a list of questions corresponding to the specified post IDs. Each item is a link that points to the question with the question's title as the link text.

id
  • Required: Yes
  • Input(s): Integer
  • ID returned by CloudDeploy.
image
  • Required: No
  • Input(s): "false".
  • Description: One common application of deployed APIs is to return an image, a plot for example. Especially the type of APIs one would like to display in a blog post. For that reason the result is automatically placed in an image tag. If the result is not an image setting image="false" will instead display the result as a string.

Any other parameter will automatically be passed on to the Wolfram Cloud API.

Working examples

Begin by deploying an API, make sure that it is public:

CloudDeploy[APIFunction[{
   "rule" -> Restricted["Number", {0, 255, 1}] -> 30, 
   "step" -> Restricted["Number", {0, Infinity, 1}] -> 50
   }, 
  ArrayPlot[CellularAutomaton[#rule, {{1}, 0}, #step], 
    Frame -> False] &,
  "PNG"
  ], Permissions -> "Public"]

Let A be the ID Mathematica returns upon deploying the API. This is the shortcode that will display the cellular automata image:

[WolframCloudAPI id="A" rule="28" step="30"]

The following API returns a string that we would like to display:

CloudDeploy[APIFunction[{"x" -> "Integer"}, FactorInteger[#x] &], Permissions -> "Public"]

If B is the API ID that Mathematica returns then the shortcode we need to use is:

[WolframCloudAPI id="B" x="43498" image="false"]

Screenshot of a blog post that displays results retrieved from Wolfram Cloud.

Formatting and highlighting

Mathematica Toolbox uses the same highlighting script as the two largest Mathematica community websites on the Internet, Mathematica.StackExchange.com and Wolfram Community. In this way you get the best highlighting available without having to touch any code to install it. For blocks of code you can use either the shortcode

[wlcode]Code goes here[/wlcode]

or the shortcode

[wlcode field="fieldName"]

where field name is the name of a meta field that contains the code. See below for a more detailed explanation.

[wlinline]code goes here[/wlinline] wraps the contained text in HTML code tags, which means that it will get a special markup in many themes. It will not be highlighted however.

When Mathematica code is copied from a notebook to a text editor special symbols like greek letters are automatically translated into a language specific format, for example \[Alpha], \[Beta] and \[Epsilon]. This more verbose format makes the code much more difficult to read. For that reason Mathematica Toolbox replaces all such codes with their appropriate glyphs.

Mathematica Toolbox also prevents WordPress from modifying the code (e.g. by inserting p and br tags) as it would have done had the code been pasted into the post editor outside of the code highlighting shortcodes.

The [wlcode field=""] shortcode

Custom fields are key-value pairs that can be attached to any WordPress post. You should find a box underneath the text editor that says "Custom Fields", if not you have to enable it in the screen options pane. If you are writing a blog post you should be able to see a button that says Screen options in the top right corner next to a button that says Help.

Once custom fields are enabled and you've found the box you can start adding pieces of code into named custom fields. The name of the custom field is the parameter field in the shortcode [wlcode field=""] that will insert the particular piece of code into the blog post wherever it is placed.

Screenshot of a highlighted piece of code in a blog post.

Screenshot of code entered into custom fields. [wlcode field="example"] and [wlcode field="glyphs"] inserts the respective pieces of code into the blog post.

Mathematica.StackExchange shortcodes

Mathematica StackExchange (sometimes written MMA.SE) is a big Q&A site for Mathematica. At the time of writing (June, 2016) there are 34 0000 questions, 52 000 answers, 26 000 registered users and 7 500 visits per day. Mathematica Toolbox provides a set of shortcodes that interact with the Mathematica StackExchange API to retrieve information about users, questions and answers. This can be useful when you are writing about something related, perhaps a "top ten questions about plotting" post. You can then use a shortcode to automatically show a list of questions given their IDs. It can also be useful if you want to post a list that will change over time, such as a list of your own most popular questions or answers. By using a shortcode the list will update automatically without you having to update it manually. The fetching of information is clever in the sense that all information is cached so it's usually not making any requests to the Mathematica StackExchange API.

Parameters

[mma_se_questions ids="..."]

Retrieves and displays a list of questions corresponding to the specified post IDs. Each item is a link that points to the question with the question's title as the link text.

ids
  • Required: Yes
  • Input(s): List of IDs separated by semicolons. For example ids="11350;3345;3646".
  • The list of IDs is used to display a list of questions. The order is preserved from the order in that the IDs appear in this parameter.
expiration
  • Required: No
  • Input(s): Integer.
  • Description: The number of seconds until the cache expires. Defaults to one month.

[mma_se_answers ids="..."]

Retrieves and displays a list of answers corresponding to the specified post IDs. Each item is a link that points to the answer with the question's title as the link text.

ids
  • Required: Yes
  • Input(s): List of IDs separated by semicolons. For example ids="25616;259".
  • The list of IDs is used to display a list of answers. The order is preserved from the order in that the IDs appear in this parameter.
expiration
  • Required: No
  • Input(s): Integer.
  • Description: The number of seconds until the cache expires. Defaults to one month.

[mma_se_user user_id="..."]

Displays the username of the user with a particular ID. This is useful because users can change their names over time, by always using this shortcode when referring to a Mathematica.StackExchange user the name will always be up to date.

user_id
  • Required: Yes
  • Input(s): Integer
  • The ID of the user.
link
  • Required: No
  • Input(s): The string "false".
  • Description: By default the name is rendered as a link to the user's profile page. To just show the name without the link, set this parameter to "false", i.e. link="false" .
expiration
  • Required: No
  • Input(s): Integer.
  • Description: The number of seconds until the cache expires. Defaults to one week.

[mma_se_profile_box user_id="..."]

Displays a box with information about the user; his username, gravatar, reputation score and how many badges of each type he has. You can display this information about yourself somewhere on the site, to show your standing on the Mathematica.StackExchange site.

user_id
  • Required: Yes
  • Input(s): Integer
  • The ID of the user.
expiration
  • Required: No
  • Input(s): Integer.
  • Description: The number of seconds until the cache expires. Defaults to one day.

[mma_se_user_questions user_id="..."]

Displays a list of questions written by the user with the specified ID.

user_id
  • Required: Yes
  • Input(s): Integer
  • The ID of the user.
expiration
  • Required: No
  • Input(s): Integer.
  • Description: The number of seconds until the cache expires. Defaults to one day.

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.

[mma_se_user_answers user_id="..."]

Displays a list of answers written by the user with the specified ID.

user_id
  • Required: Yes
  • Input(s): Integer
  • The ID of the user.
expiration
  • Required: No
  • Input(s): Integer.
  • Description: The number of seconds until the cache expires. Defaults to one day.

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_answers 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.

Screenshot of a profile box as displayed by [mma_se_profile_box user_id="731"].

Screenshot from a blog using a variety of different shortcodes to display up to date listings of a user's top questions and answers, and the user's name.

Extras

The shortcode

[wldoc]function[/wldoc]

displays a link to the documentation of the function that it is given.