Giter Club home page Giter Club logo

asciimath's Introduction

PreTeXt AsciiMath to LaTeX

This project is an extension to the PreTeXt MathBook XML project. It provides a convenient way for PreTeXt authors to convert AsciiMath to LaTeX.

Please install Python 2.7 and xsltproc before continuing.

Getting started

Clone this repository. Then, clone mathbook repository to access PreTeXt source, including a sample book and article.

$ git clone https://github.com/ymittal/asciimath
$ cd asciimath
$ git clone https://github.com/rbeezer/mathbook
$ virtualenv .env && source .env/bin/activate   # (optional) setup virtualenv
$ pip install -r requirements.txt               # setup pip dependencies
$ chmod +x pretext.sh

Run this command to convert AsciiMath markup, written as <m>`asciimath goes here</m> in <XML>, to LaTeX. It also runs xsltproc with any arguments specified after ./pretext.sh.

$ ./pretext.sh -o <output_dir> <STYLESHEET> <XML>

Check this for xsltproc documentation.

Example

This command converts AsciiMath markup in files in samples folder, stores new XML files to samples-latex folder and generates HTML files into generated-html folder using xsltproc.

$ ./pretext.sh -o generated-html/ mathbook/xsl/mathbook-html.xsl samples/asciimath.xml

Notes

  • All files in samples remain unchanged lest the pretext.sh script unexpectedly modify the source XML.
  • AsciiMath to LaTeX conversion is done only on files with .xml, .ptx extensions in samples. Other files are copied to samples-latex as is.

Sample XML file with AsciiMath

To check the AsciiMath to LaTeX conversion on a single XML file, run

$ python replace.py --xml samples/asciimath.xml

Contact

Please feel free to contact Yash Mittal or create an issue if you have questions regarding this project.

asciimath's People

Contributors

davidfarmer avatar dependabot[bot] avatar ymittal avatar

Watchers

 avatar  avatar  avatar

asciimath's Issues

Incorrect latex conversion in replace.py

Running this command from README results in weird output.

$ python replace.py --xml samples/asciimath.xml

For example, <m>`sqrt(2) + root 3 2</m> changes to <m>\sqrt{2} \sqrt[3]{2}</m> instead of the expected <m>\sqrt{2} + \sqrt[3]{2}</m>. I see the expected output when I run src/replace.py standalone.

Compound expressions in certain function arguments, and elsewhere?

Some functions are commonly written without parentheses around their
arguments in certain cases, such as

cos 2pi = 1

A convention which seems workable is to consider the argument to continue
until white space or the end of the expression.

The some convention would interpret
e^2x as exp(2x)

Another situation where a similar convention might be workable is in limits
of integrals as in

int_0^2pi cos x dx = 0 .

Except that it would be weird to allow that in the lower limit but not the upper
limit:

int_18pi^26pi sin x = 0

There it is the ^ and not a space that signals the end of the lower limit.

But if that works, then why not

sum_n=1^infty n^-2 = pi/6 ?

I am not advocating either way. I find
sum_n=1^infty harder to read than sum_(n=1)^infty
so maybe there is nothing to be gained by allowing that flexibility everywhere.

It would be nice to have a sharp line delimiting when such grouping has
parentheses optional. Maybe this will become clearer as we test more examples.

Less than needs to be \lt in XML

The expression

5 < 6

is valid LaTeX, but including that in a PreTeXt document gives an error
because the less-than character is special in XML.

So unlike standard AsciiMath, in PXT the conversion needs to
write it as

5 \lt 6

e^sin(x^2)

Asciimth displays it correctly, LaTeX does not. Our existing implementation should display it as e^{sin(x^2)}.

Objects with multiple pieces

An expression like cos(3 x) has two pieces, and we will need a
way to recognize it as one object with two pieces:
the function cosine and its argument.

int 3 x dx has 3 pieces:
(the integral) (of 3 x) (dx)
[do I mean "the antiderivative"?]

log_10(300) has three pieces:
(the log) (base 10) (of 300)

sum_(n=1)^55 3 n has 4 pieces:
(the sum) (from n=1) (to 55) (of 3n)

int_0^1 3 x dx has 5 pieces:
(the integral) (from 0) (to 1) (of 3 x) (dx)

I'd like to discuss what input we need in order to parse these
properly.

In each case, once you identify the base object,
only a few things can happen, and you have to look past a
predetermined number of other objects to determine what
is going on. Once you have the pieces, you understand the
complete object. Then you are ready to do something with it,
such as output to semantic LaTeX.

Decimals

numbers are restricted to integers, add support for decimals :)

Angle brackets

Inner products are usually written with angle brackets. It looks sort of like this:
<u,v>
except that the delimiters are not angled as sharply. In TeX it is written
\langle u,v\rangle

You might think that AsciiMath would just use the less-than and greater-than
signs, but they can't because of their parsing rules. They offer two options:
shown here:

<<u,v>> or (:u,v:)

I don't like either of those.

If we insist that the less-than sign, when used as a relation,
have spaces around it, then we are free to let people use a more natural
input for inner product.

There are various other special uses of < and > that need to be taken
into account:
<=, >=, =>, <=>, ->, more

Does this seem workable?

dy/dx

Standard AM recognizes d/dx and dy/dx as the fractions \frac{d}{dx} and \frac{dy}{dx} .

I think that behavior should be replicated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.