Skip to content

Commit fafebc1

Browse files
author
hornik
committed
Fix PR#18855 issue 7. By Duncan Murdoch.
git-svn-id: https://svn.r-project.org/R/trunk@87801 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 93abcc2 commit fafebc1

File tree

6 files changed

+444
-150
lines changed

6 files changed

+444
-150
lines changed

src/library/tools/R/parseLatex.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Part of the R package, https://www.R-project.org
33
#
44
# Copyright (C) 1995-2023 The R Core Team
5+
# Copyright (C) 2025 Duncan Murdoch
56
#
67
# This program is free software; you can redistribute it and/or modify
78
# it under the terms of the GNU General Public License as published by
@@ -19,12 +20,23 @@
1920
parseLatex <- function(text, filename = "text",
2021
verbose = FALSE, verbatim = c("verbatim", "verbatim*",
2122
"Sinput", "Soutput"),
22-
verb = "\\Sexpr")
23+
verb = "\\Sexpr",
24+
defcmd = c("\\newcommand", "\\renewcommand",
25+
"\\providecommand", "\\def", "\\let"),
26+
defenv = c("\\newenvironment",
27+
"\\renewenvironment"))
2328
{
2429
## the internal function must get some sort of srcfile
2530
srcfile <- srcfilecopy(filename, text)
2631
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)
2840
}
2941

3042

@@ -58,6 +70,7 @@ deparseLatex <- function(x, dropBraces = FALSE)
5870
"\\end{", a[[1L]], "}"),
5971
MATH = c("$", Recall(a), "$"), # \( and \) parse as MACRO
6072
DISPLAYMATH = c("$$", Recall(a), "$$"),
73+
DEFINITION = Recall(a),
6174
NULL = stop("Internal error, no tag", domain = NA)
6275
))
6376
lastTag <- tag

src/library/tools/man/parseLatex.Rd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ parseLatex(text, filename = "text",
2020
verbose = FALSE,
2121
verbatim = c("verbatim", "verbatim*",
2222
"Sinput", "Soutput"),
23-
verb = "\\\\Sexpr")
23+
verb = "\\\\Sexpr",
24+
defcmd = c("\\\\newcommand", "\\\\renewcommand",
25+
"\\\\providecommand", "\\\\def", "\\\\let"),
26+
defenv = c("\\\\newenvironment",
27+
"\\\\renewenvironment"))
2428
deparseLatex(x, dropBraces = FALSE)
2529
latexToUtf8(x)
2630
}
@@ -40,6 +44,10 @@ A character vector containing the names of LaTeX environments holding verbatim t
4044
\item{verb}{
4145
A character vector containing LaTeX macros that should be
4246
assumed to hold verbatim text.
47+
}
48+
\item{defcmd, defenv}{
49+
Character vectors containing LaTeX macros that should be assumed
50+
to define macros or environments respectively.
4351
}
4452
\item{x}{
4553
A \code{"LaTeX"} object.

0 commit comments

Comments
 (0)