Home

Awesome

MathB

MathB is a mathematics pastebin software that powers MathB.in. It is a web-based service meant for sharing snippets of mathematical text with others on the world wide web. Visit https://mathb.in/ to use the mathematics pastebin.

Contents

Features

Quick Start

This section explains how to run this project locally. The steps assume a macOS, Debian, or Debian-based Linux distribution. However, it should be possible to adapt these steps for another operating system.

  1. Install SBCL and Git.

    On macOS, enter the following command if you have Homebrew:

    brew install sbcl git
    

    On Debian, Ubuntu, or another Debian-based Linux system, enter the following command:

    sudo apt-get update
    sudo apt-get install sbcl git
    
  2. Install Quicklisp with the following commands:

    curl -O https://beta.quicklisp.org/quicklisp.lisp
    sbcl --load quicklisp.lisp --eval "(quicklisp-quickstart:install)" --quit
    sbcl --load ~/quicklisp/setup.lisp --eval "(ql:add-to-init-file)" --quit
    
  3. From here on, we assume that all commands are being run in the top-level directory of this project. Set up dependencies necessary to run this project by running this command within the top-level directory of this project:

    make live
    

    This creates a _live directory within the current directory and copies all necessary dependencies to it.

  4. Create data and log directories:

    sudo mkdir -p /opt/data/mathb/ /opt/log/mathb/
    sudo cp -R meta/data/* /opt/data/mathb/
    sudo chown -R "$USER" /opt/data/mathb/ /opt/log/mathb/
    

    By default, MathB reads post data from and writes posts to /opt/data/mathb/. It writes logs to /opt/log/mathb/ by default. The next section explains how to make it use custom directory paths.

  5. Run MathB with the following command:

    sbcl --load mathb.lisp
    
  6. Visit http://localhost:4242/ with a web browser to use MathB.

After starting MathB in this manner, click on the various navigation links and make a new post to confirm that MathB is working as expected.

Custom Directory Paths

In the previous section, we created a data directory at /opt/data/mathb/ and a log directory at /opt/log/mathb/. By default, MathB writes new posts to and reads posts from this directory path. To make it use a different path for the data directory, set the variable named *data-directory* before loading it. Similarly, set the variable named *log-directory* to specify a different path for the log directory. The following steps demonstrate how to do this:

  1. Create data directory at a custom path, say, at ~/data:

    mkdir -p ~/data/ ~/log/
    cp -R meta/data/* ~/data/
    
  2. Run MathB with the following command:

    sbcl --eval '(defvar *data-directory* "~/data/")' \
         --eval '(defvar *log-directory* "~/log/")' \
         --load mathb.lisp
    
  3. Visit http://localhost:4242/ with a web browser to use MathB.

After starting MathB in this manner, click on the various navigation links and make a new post to confirm that MathB is working as expected.

Data Files

The data directory contains the following files:

In the last point, the placeholder X is the post ID divided by 1000000. The placeholder Y is the post ID divided by 1000. For example, for a post with ID 1, X is 0 and Y is 0, so a post with this ID is saved at post/0/0/1.txt. For a more illustrative example, consider a post with with ID 2301477. Now X is 2 and Y is 2301, so a post with this ID is saved at post/2/2301/2301477.txt.

Let us call each X directory a short-prefix directory and each Y directory under it a long-prefix directory. As a result of the calculation explained above, each short-prefix directory contains a maximum of 1000 long-prefix directories and each long-prefix directory contains a maximum of 1000 post files. Thus, each short-prefix directory contains a maximum of one million post files under it.

Runtime Options

MathB reads runtime properties from opt.lisp. This file contains a property list. Each property in this list is followed by a value for that property. This property list may be used to alter the behaviour of MathB. A list of all supported properties and their descriptions is provided below.

If a property name is missing from this file or if the file itself is missing, then the default value of the property mentioned within parentheses above is used.

Whenever a post is rejected due to a runtime option, the entire input form is returned intact to the client with an error message, so that they can fix the errors or wait for the suggested post interval and resubmit the post again.

The property values in opt.lisp may be modified at any time, even while MathB is running. It is not necessary to restart MathB after changing property values in opt.lisp. The changes are picked up automatically while processing the next HTTP POST request.

Template Files

There are two template files to generate the HTML pages sent to the clients:

A template file may be modified at any time, even while MathB is running. It is not necessary to restart MathB after changing a template file. The changes are picked up automatically while processing the next HTTP request.

Static Files

There are three types of static files that MathB uses to for its HTML pages:

A static file may be modified at any time, even while MathB is running. It is not necessary to restart MathB after adding, deleting, or editing a static file. However, it is necessary to run make live (in the top-level directory of the project) to copy the static files to the live directory (explained in the next section) from which MathB serves the static files.

Live Directory

MathB needs to pull additional JavaScript libraries named TeXMe, Marked, and MathJax that are essential for rendering Markdown and LaTeX input. This is done by running the following command in the top-level directory of this project:

make live

The above command creates a _live directory from scratch, copies the static files to it, then pulls the additional JavaScript libraries into it, and sets up the _live directory, so that MathB can serve the static files from it.

The live directory should never be modified directly because every make live run deletes the entire directory and creates it from scratch again. Any modification necessary should be made to the template files or static files explained in the previous two sections.

Print

While the primary purpose of this project is to allow users to write mathematical snippets, save them, and share a link to them with others, the stylesheet used in this project takes special care to allow printing beautifully rendered pages to paper.

When a MathB page is printed, only the rendered content appears in the print. The input form, buttons, navigation links, and other user interface elements do not appear in the print.

Save PDF

It is possible to turn a MathB post into a PDF file using the printing facility of most web browsers running on a desktop or laptop. The exact steps to save a web page as PDF vary from browser to browser but the steps to do so look roughly like this:

If everything works as expected, the saved PDF should contain only the rendered content with all mathematical formulas rendered properly. The web pages generated by this project use special styling rules to ensure that the input form, buttons, navigation links, and other user interface elements do not appear in saved PDF.

History

MathB.in is the oldest mathematics pastebin that is still online and serving its community of users. It isn't the first mathematics pastebin though. It's the second. The first pastebin was written by Mark A. Stratman. It was hosted at the domain mathbin.net until 2020.

MathB.in was born on Sunday, 25 March 2012, after a single night of furious coding. This was a result of stumbling upon math.stackexchange.com the previous night which used MathJax to render mathematics formula on the web browser. Thanks to that chance encounter with MathJax, the rest of the Saturday night was spent in coding a new mathematics pastebin using MathJax and PHP. After coding all through the night, registering a new domain name, and setting up a website, MathB.in was released early Sunday morning.

The current version of MathB.in no longer runs on PHP. It has been rewritten in Common Lisp since then. See the blog post MathB.in Turns Ten for more details about the history of MathB.in.

License

This is free and open source software. You can use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of it, under the terms of the MIT License. See LICENSE.md for details.

This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or implied. See LICENSE.md for details.

Support

To report bugs, suggest improvements, or ask questions, create issues.

Channels

The author of this project hangs out at the following places online:

You are welcome to subscribe to, follow, or join one or more of the above channels to receive updates from the author or ask questions about this project.

More

If you like this project, check out related projects TeXMe and Muboard.