=== Plugin Name ===
Contributors: C. E.
Donate link: 
Tags: CDF, Computable Document Format, Mathematica, Wolfram Language, Stack Exchange, syntax highlighter
Requires at least: 3.0.1
Tested up to: 4.2.2
Stable tag: 1.0.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Syntax highlighting for Mathematica code. Automated CDF embedding. Wolfram Cloud API utility shortcode. Seamless cached interface to Mathematica.SE.

== Description ==

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](http://mathematica.stackexchange.com) and on [Wolfram Community](http://community.wolfram.com).
* 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](https://wordpress.org/plugins/wolfram-cdf-plugin/) from Wolfram Research that embeds CDFs [does not work](http://mathematica.stackexchange.com/q/66311/731) 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](http://api.stackexchange.com/docs/answers-by-ids) 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](https://github.com/halirutan/Mathematica-Source-Highlighting) wrote the Google Code Prettify extension for Mathematica. He also wrote [this](http://meta.mathematica.stackexchange.com/questions/1043/additional-useful-buttons-for-our-m-se-editor/) 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](http://wppb.io/) 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`.

== Installation ==

1. Upload the folder `Mathematica-Toolbox` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress

You should now be able to use any of the shortcodes. If you forget what they are you can use the buttons that should have appeared underneath the text editor to insert shortcode templates into the text.

== Frequently Asked Questions ==

= What are the allowed parameters of `mma_se_user_*` shortcodes? =

The allowed parameters can be found in the [Stack Exchange API documentation](http://api.stackexchange.com/docs/answers-by-ids). Both the retrieval of questions and answers make use of the same parameters. Additionally a filter, as defined in the Stackexchange API documentation, can be specified. And `expiration` - the lifetime of a cached value given in the number of seconds - can also be specified.

= What are the default cache expiration times for Stack Exchange date? =
When data is retrieved from Stack Exchange using a `mma_se_*` shortcode and no expiration time for the cache is given, the following expiration times are assumed:
* `mma_se_user` is renewed once every week.
* `mma_se_user_*` is renewed once every day.
* `mma_se_(questions|answers)` is renewed once every month.
* `mma_se_profile_box` is renewed once every day.

= Examples of how to show the result of an instant API =
For example,

    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"]

and

    CloudDeploy[APIFunction[{"x" -> "Integer"}, FactorInteger[#x] &], Permissions -> "Public"]
    
can be called in a post using

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

and

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

where A is the ID corresponding to the cellular automata API and B is the ID corresponding to the factorization API.

== Screenshots ==

1. CDFs can be included in WordPress posts, as well as data and images from Wolfram Cloud APIs.
2. There are two different ways to include highlighted code blocks, but they produce the same result. Character codes such as `\[Alpha]` get replaced automatically with their corresponding characters.
3. Handy shortcodes can render usernames and links to the online documentation.
4. Shortcodes that interface with the Stackexchange API can retrieve information about a user. `[mma_se_profile_box user_id="731"]` creates the profile box seen in the image.
5. Answers specified by IDs, retrieved from the Stackexchange API.
6. The top metabox is the "toolbox" which the plugin is named after. A click on one of those buttons inserts the corresponding shortcode into the editor. Below the toolbox there is an example of code in custom post fields, which can be included in the post using `[wlcode field="example"]` and `[wlcode field="glyphs"]` respectively.

== Changelog ==

**Version 1.0.2**

Release date: 13th September, 2015

* Fixed a problem with the `WolframCloudAPI` shortcode with custom parameters.

**Version 1.0.1**

Release date: 17th July, 2015

* Inline code shortcode. Used to get special markup for inline code.
* Fixed incorrect title attributes of some of the shortcode buttons.

== Upgrade Notice ==
