Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ $ go get -u github.com/nyttikord/gomath@latest
```
You can replace `latest` with any valid tags.

You can install a CLI with
```bash
$ go install github.com/nyttikord/gomath/cmd@latest
```
You can replace `latest` with any valid tags.

### Calculate

To parse an expression and calculate it, use `gomath.ParseAndCalculate(string, *gomath.Options) (string, error)`.
Expand Down Expand Up @@ -38,6 +44,14 @@ err == nil // true
res == `\frac{1 + \frac{2}{3}}{2}` // true
```

### CLI

You can get the help with `gomath help`.
Comment thread
leo-210 marked this conversation as resolved.

To evaluate an expression, use `gomath eval <expression>`.

To convert to $\LaTeX$ an expression, use `gomath latex <expression>`.
Comment thread
anhgelus marked this conversation as resolved.
Outdated

### Special case

The written representation of calculation is definitely not compatible with computers.
Expand Down
50 changes: 50 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"fmt"
"github.com/nyttikord/gomath"
"os"
"strings"
)

func main() {
if len(os.Args) < 2 {
fmt.Printf("Usage: %s <subcommand>\nUse %s help to get the help.\n", os.Args[0], os.Args[0])
Comment thread
anhgelus marked this conversation as resolved.
Outdated
os.Exit(1)
}
subcommand := os.Args[1]
switch subcommand {
case "help":
if len(os.Args) != 2 {
fmt.Printf("Help does not take any arguments.\n")
Comment thread
anhgelus marked this conversation as resolved.
Outdated
os.Exit(1)
}
fmt.Printf("Subcommands:\n- eval <expression> -> evaluate an expression.\n- latex <expression> -> latexify an expression.\n")
Comment thread
anhgelus marked this conversation as resolved.
Outdated
case "eval":
if len(os.Args) < 3 {
fmt.Printf("Usage: %s eval <expression>.\n", os.Args[0])
os.Exit(1)
}
expression := strings.Join(os.Args[2:], " ")
res, err := gomath.Parse(expression)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
fmt.Println(res)
case "latex":
if len(os.Args) < 3 {
fmt.Printf("Usage: %s latex <expression>.\n", os.Args[0])
os.Exit(1)
}
expression := strings.Join(os.Args[2:], " ")
res, err := gomath.ParseAndConvertToLaTeX(expression, nil)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
fmt.Println(res)
default:
fmt.Printf("Unknown subcommand: %s\nUse %s help to get the help.\n", subcommand, os.Args[0])
Comment thread
anhgelus marked this conversation as resolved.
Outdated
}
}
Loading