Skip to content

Commit 81c4965

Browse files
committed
remove macro including char '@' raahii#3
1 parent f3ecd9f commit 81c4965

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Diff for: controllers/papers.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func resolveInputs(mainLatexPath string, basePath string) (string, error) {
6868
commands := []string{
6969
`\input`,
7070
`\include`,
71+
`\usepackage`,
7172
}
7273

7374
// replace the command with actual file content
@@ -88,11 +89,23 @@ func resolveInputs(mainLatexPath string, basePath string) (string, error) {
8889
// read path in the brace
8990
path := source[startIndex+len(com) : endIndex-1]
9091
if filepath.Ext(path) == "" {
91-
path = path + ".tex"
92+
if strings.Contains(com, `\usepackage`) {
93+
path = path + ".sty"
94+
} else {
95+
path = path + ".tex"
96+
}
97+
}
98+
99+
path = filepath.Join(basePath, path)
100+
101+
if _, err := os.Stat(path); os.IsNotExist(err) {
102+
// remove the command
103+
source = source[:startIndex] + source[endIndex:]
104+
continue
92105
}
93106

94107
// read file content
95-
_source, err := readFile(filepath.Join(basePath, path))
108+
_source, err := readFile(path)
96109
if err != nil {
97110
return "", err
98111
}
@@ -184,6 +197,10 @@ func (paper *Paper) readLatexSource(path string) error {
184197
}
185198
macros := []Macro{}
186199
for _, str := range macroStrs {
200+
if strings.Contains(str, "@") {
201+
continue
202+
}
203+
// extract command part, ex) \def\bm... -> \bm
187204
s := 3 + strings.Index(str[3:], `\`)
188205
e := len(str)
189206
for _, c := range []string{` `, `}`, `{`, `[`} {

0 commit comments

Comments
 (0)