Skip to content

Commit

Permalink
Merge pull request #277 from mrob95/LaTeX_complete
Browse files Browse the repository at this point in the history
Added a LaTeX ccr module
  • Loading branch information
LexiconCode authored Oct 11, 2018
2 parents 80616a5 + a3b9171 commit 340b55c
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 0 deletions.
14 changes: 14 additions & 0 deletions caster/doc/readthedocs/CCR languages quick reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A quick reference guide for the language-specific commands included with Caster.
* [HTML](#html)
* [Java](#java)
* [Javascript](#javascript)
* [LaTeX](#latex)
* [Matlab](#matlab)
* [Prolog](#prolog)
* [Python](#python)
Expand Down Expand Up @@ -256,6 +257,19 @@ instance of|`instanceof `||while loop|`while ()`
length|`length`|||``


# LaTeX
Commands are designed to follow LaTeX syntax as closely as possible, for example `insert document class` produces `\documentclass{}`. See lines 69- of caster/lib/ccr/latex/latex.py for a full list of available inputs.

Command | Output | | Command | Output
---|---|---|---|---
`[use] package [<packages>]`|`\usepackage{<packages>}`||insert quote|\`\`''
[use] package bib latex|`\usepackage[style=authoryear]{biblatex}`||math fraction|`\frac{}{} `
add comment|`%`||subscript|`_{}`
`begin <element>`|`\begin{<element>}` </br> </br> `\end{<element>}`||superscript|`^{}`
`insert <command>`|`\<command>{}`||`symbol [<big>] <symbol>`|`\<symbol>`
`insert <commandnoarg>`|`\<commandnoarg>`|||``


# Matlab
Command | Output | | Command | Output
---|---|---|---|---
Expand Down
1 change: 1 addition & 0 deletions caster/lib/ccr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"html.html": ("HTML", ),
"java.java": ("Java", ),
"javascript.javascript": ("Javascript", ),
"latex.latex": ("LaTeX", ),
"matlab.matlab": ("Matlab", ),
"python.python": ("Python", ),
"r.r": ("Rlang", ),
Expand Down
Empty file.
194 changes: 194 additions & 0 deletions caster/lib/ccr/latex/latex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
'''
Created on Sep 4, 2018
@author: Mike Roberts
'''
from dragonfly import Function, Choice, Key, Text

from caster.lib import control
from caster.lib.dfplus.merge.mergerule import MergeRule
from caster.lib.dfplus.state.short import R
from caster.lib.ccr.standard import SymbolSpecs


# Return \first{second}, if second is empty then end inside the brackets for user input
def back_curl(first, second):
if str(second) != "":
return (Text("\\") + Text(str(first)) + Key("lbrace, rbrace, left") + Text(
str(second)) + Key("right"))
if str(second) == "":
return (Text("\\") + Text(str(first)) + Key("lbrace, rbrace, left"))


def symbol_letters(big, symbol):
if big == "big":
symbol = symbol.title()
Text(str(symbol)).execute()


class LaTeX(MergeRule):
pronunciation = "latex"

mapping = {
SymbolSpecs.COMMENT:
R(Text("%"), rdescript="LaTeX: Add Comment"),
"begin <element>":
R(back_curl("begin", "%(element)s") + Key("enter:2") + back_curl(
"end", "%(element)s") + Key("up"),
rdescript="LaTeX: Define beginning and end of an element"),
#
"[use] package [<packages>]":
R(back_curl("usepackage", "%(packages)s"), rdescript="LaTeX: Import packages"),
"[use] package bib latex":
R(back_curl("usepackage[style=authoryear]", "biblatex"),
rdescript="LaTeX: Import biblatex package"),
#
"symbol [<big>] <symbol>":
R(Text("\\") + Function(symbol_letters, extra={"big", "symbol"}) + Text(" "),
rdescript="LaTeX: Insert symbols"),
#
"insert <command>":
R(back_curl("%(command)s", ""),
rdescript="LaTeX: Insert command requiring an argument"),
"insert <commandnoarg>":
R(Text("\\%(commandnoarg)s "),
rdescript="LaTeX: Insert command not requiring an argument"),
"insert quote":
R(Text("``\'\'") + Key("left:2"), rdescript="LaTeX: Insert a quote"),
#
"superscript":
R(Text("^") + Key("lbrace, rbrace, left"), rdescript="LaTeX: Superscript"),
"subscript":
R(Text("_") + Key("lbrace, rbrace, left"), rdescript="LaTeX: Subscript"),
"math fraction":
R(Text("\\") + Text("frac") +
Key("lbrace, rbrace, lbrace, rbrace, space, left:4"),
rdescript="LaTeX: Fraction"),
}

extras = [
Choice("packages", {
"math tools": "mathtools",
"graphic ex": "graphicx",
"wrap figure": "wrapfig",
}),
Choice(
"element", {
"center": "center",
"columns": "columns",
"description": "description",
"document": "document",
"(enumerate | numbered list)": "enumerate",
"equation": "equation",
"figure": "figure",
"flush left": "flushleft",
"flush right": "flushright",
"frame": "frame",
"list": "list",
"mini page": "minipage",
"quotation": "quotation",
"quote": "quote",
"table": "table",
"title page": "titlepage",
"verbatim": "verbatim",
"verse": "verse",
"wrap figure": "wrapfigure",
}),
Choice(
"command", {
"author": "author",
"[add] bib resource": "addbibresource",
"caption": "caption",
"chapter": "chapter",
"column": "column",
"document class": "documentclass",
"graphics path": "graphicspath",
"[include] graphics": "includegraphics[width=1\\textwidth]",
"label": "label",
"new command": "newcommand",
"paragraph": "paragraph",
"paren cite": "parencite",
"part": "part",
"reference": "ref",
"sub paragraph": "subparagraph",
"(section | heading)": "section",
"sub (section | heading)": "subsection",
"sub sub (section | heading)": "subsubsection",
"text cite": "textcite",
"[text] bold": "textbf",
"[text] italics": "textit",
"[text] slanted": "textsl",
"title": "title",
"use theme": "usetheme",
}),
Choice(
"commandnoarg", {
"line break": "linebreak",
"[list] item": "item",
"make title": "maketitle",
"new page": "newpage",
"page break": "pagebreak",
"print bibliography": "printbibliography",
"table of contents": "tableofcontents",
"text width": "textwidth",
}),
Choice(
"symbol",
{
"alpha": "alpha",
"beater": "beta",
"gamma": "gamma",
"delta": "delta",
"epsilon": "epsilon",
"zita": "zeta",
"eater": "eta",
"theta": "theta",
"iota": "iota",
"kappa": "kappa",
"lambda": "lambda",
"mu": "mu",
"new": "nu",
"zee": "xi",
"pie": "pi",
"row": "rho",
"sigma": "sigma",
"tau": "tau",
"upsilon": "upsilon",
"phi": "phi",
"chi": "chi",
"sigh": "psi",
"omega": "omega",
#
"times": "times",
"divide": "div",
"intersection": "cap",
"union": "cup",
"stop": "cdot",
"approximate": "approx",
"proportional": "propto",
"not equal": "neq",
"member": "in",
"for all": "forall",
"partial": "partial",
"infinity": "infty",
"dots": "dots",
#
"left arrow": "leftarrow",
"right arrow": "rightarrow",
"up arrow": "uparrow",
"down arrow": "downarrow",
#
"left": "left(",
"right": "right)",
}),
Choice("big", {
"big": "big",
}),
]
defaults = {
"big": "",
"packages": "",
}


control.nexus().merger.add_global_rule(LaTeX())

0 comments on commit 340b55c

Please sign in to comment.