|  | 
| 2 | 2 | #  Part of the R package, https://www.R-project.org | 
| 3 | 3 | # | 
| 4 | 4 | #  Copyright (C) 1995-2023 The R Core Team | 
|  | 5 | +#  Copyright (C) 2025 Duncan Murdoch | 
| 5 | 6 | # | 
| 6 | 7 | #  This program is free software; you can redistribute it and/or modify | 
| 7 | 8 | #  it under the terms of the GNU General Public License as published by | 
|  | 
| 19 | 20 | parseLatex <- function(text, filename = "text", | 
| 20 | 21 |                      verbose = FALSE, verbatim = c("verbatim", "verbatim*", | 
| 21 | 22 |                      "Sinput", "Soutput"), | 
| 22 |  | -		     verb = "\\Sexpr") | 
|  | 23 | +		     verb = "\\Sexpr", | 
|  | 24 | +		     defcmd = c("\\newcommand", "\\renewcommand", | 
|  | 25 | +		     	   "\\providecommand", "\\def", "\\let"), | 
|  | 26 | +		     defenv = c("\\newenvironment", | 
|  | 27 | +		     	   "\\renewenvironment")) | 
| 23 | 28 | { | 
| 24 | 29 |     ## the internal function must get some sort of srcfile | 
| 25 | 30 |     srcfile <- srcfilecopy(filename, text) | 
| 26 | 31 |     text <- paste(text, collapse="\n") | 
| 27 |  | -    .External2(C_parseLatex, text, srcfile, verbose, as.character(verbatim), as.character(verb)) | 
|  | 32 | +     | 
|  | 33 | +    keywords <- c(as.character(verb), as.character(defcmd), | 
|  | 34 | +    	      as.character(defenv)) | 
|  | 35 | +    # types:  1=verb, 2=defcmd, 3=defenv | 
|  | 36 | +    keywordtype <- rep(1:3, c(length(verb), length(defcmd), | 
|  | 37 | +    			  length(defenv))) | 
|  | 38 | +     | 
|  | 39 | +    .External2(C_parseLatex, text, srcfile, verbose, as.character(verbatim), keywords, keywordtype) | 
| 28 | 40 | } | 
| 29 | 41 | 
 | 
| 30 | 42 | 
 | 
| @@ -58,6 +70,7 @@ deparseLatex <- function(x, dropBraces = FALSE) | 
| 58 | 70 |         	"\\end{", a[[1L]], "}"), | 
| 59 | 71 |         MATH = c("$", Recall(a), "$"), # \( and \) parse as MACRO | 
| 60 | 72 |         DISPLAYMATH = c("$$", Recall(a), "$$"), | 
|  | 73 | +        DEFINITION = Recall(a), | 
| 61 | 74 |         NULL = stop("Internal error, no tag", domain = NA) | 
| 62 | 75 |         )) | 
| 63 | 76 |         lastTag <- tag | 
|  | 
0 commit comments