You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.7 KiB

4 weeks ago
package main
import (
"fmt"
"github.com/urfave/cli"
"github.com/zhexiao/mtef-go/docx"
"github.com/zhexiao/mtef-go/eqn"
"log"
"os"
"time"
)
func main() {
var filepath, docxDocument, outputFile string
app := cli.NewApp()
app.Name = "Mtef"
app.Usage = "Convert MSDocx Mathtype Ole object to Latex code"
app.Version = "2.0"
app.EnableBashCompletion = true
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "filepath, f",
Usage: "Mathtype Ole object filepath",
Destination: &filepath,
},
cli.StringFlag{
Name: "wordDocx, w",
Usage: "Office word docx documents",
Destination: &docxDocument,
},
cli.StringFlag{
Name: "output, o",
Usage: "Output file path",
Destination: &outputFile,
},
}
app.Action = func(c *cli.Context) error {
var result string
var err error
if filepath != "" {
if _, err = os.Stat(filepath); os.IsNotExist(err) {
fmt.Println("File not exist!!!!")
return nil
}
result = eqn.Convert(filepath)
} else if docxDocument != "" {
if _, err = os.Stat(docxDocument); os.IsNotExist(err) {
fmt.Println("File not exist!!!!")
return nil
}
dw := docx.DocxWord{
Filename: docxDocument,
Target: fmt.Sprintf("/tmp/%v", time.Now().UnixNano()),
}
result, err = dw.ParseDocx()
if err != nil {
return err
}
}
if outputFile != "" {
err = os.WriteFile(outputFile, []byte(result), 0644)
if err != nil {
return fmt.Errorf("failed to write output: %v", err)
}
fmt.Printf("Output saved to %s\n", outputFile)
} else {
fmt.Println(result)
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Panic(err)
}
}