Skip to content

Commit d2a89d8

Browse files
author
smeyer
committed
allow markup in Rd \link text
git-svn-id: https://svn.r-project.org/R/trunk@87442 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 0391ef6 commit d2a89d8

File tree

10 files changed

+38
-26
lines changed

10 files changed

+38
-26
lines changed

share/texmf/tex/latex/Rd.sty

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%%% Rd.sty ... Style for printing the R manual
22
%%% Part of the R package, https://www.R-project.org
3-
%%% Copyright (C) 2003-2022 The R Foundation
3+
%%% Copyright (C) 2003-2024 The R Foundation
44
%%% Distributed under GPL 2 or later
55
%%%
66
%%% Modified 1998/01/05 by Friedrich Leisch
@@ -416,7 +416,10 @@
416416
\ifthenelse{\boolean{Rd@use@hyper}}
417417
{\newcommand{\LinkA}[2]{\hyperlink{Rfn.#2}{#1}\index{#1@\texttt{#1}|textit}}}
418418
{\newcommand{\LinkA}[2]{#1\index{#1@\texttt{#1}|textit}}}
419-
%
419+
% \LinkB has no indexing. (added in R 4.5.0)
420+
\ifthenelse{\boolean{Rd@use@hyper}}
421+
{\newcommand{\LinkB}[2]{\hyperlink{Rfn.#2}{#1}}}
422+
{\newcommand{\LinkB}[2]{#1}}
420423
% \alias{<alias>}{<header>}
421424
\ifthenelse{\boolean{Rd@use@hyper}}
422425
{\newcommand{\aliasA}[3]{\hypertarget{Rfn.#3}{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}}}

src/library/base/man/Bessel.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ besselY(x, nu)
108108
}
109109
\seealso{
110110
Other special mathematical functions, such as
111-
\code{\link{gamma}}, \eqn{\Gamma(x)}, and \code{\link{beta}},
112-
\eqn{B(x)}.
111+
\ifelse{text}{\code{gamma}}{\link[=gamma]{\eqn{\Gamma(x)}}} and
112+
\ifelse{text}{\code{beta}}{\link[=beta]{\eqn{B(a,b)}}}.
113113
}
114114
\author{
115115
Original Fortran code:

src/library/tools/R/Rd.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ function(x)
850850
tag <- attr(e, "Rd_tag")
851851
if(identical(tag, "\\link")) {
852852
val <- if(length(e)) { # mvbutils has empty links
853-
arg <- paste(vapply(e, trimws, ""), collapse = " ")
853+
arg <- paste(trimws(unlist(e)), collapse = " ")
854854
opt <- attr(e, "Rd_option")
855855
c(arg, if(is.null(opt)) "" else as.character(opt))
856856
} else c("", "")

src/library/tools/R/Rd2HTML.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ get_link <- function(arg, tag, Rdfile) {
2929
## \link[pkg:bar]{foo} means show foo and link to topic/file bar in package pkg.
3030
## As from 2.10.0, look for topic 'bar' if file not found.
3131
## As from 4.1.0, prefer topic 'bar' over file 'bar' (in which case 'targetfile' is a misnomer)
32+
## As from 4.5.0, allow markup in link text for variants 2 and 4.
3233

33-
if (!all(RdTags(arg) == "TEXT"))
34-
stopRd(arg, Rdfile, "Bad \\link text")
35-
34+
isTEXT <- all(RdTags(arg) == "TEXT")
3635
option <- attr(arg, "Rd_option")
3736

3837
topic <- dest <- paste(unlist(arg), collapse = "")
@@ -41,16 +40,21 @@ get_link <- function(arg, tag, Rdfile) {
4140
if (!is.null(option)) {
4241
if (!identical(attr(option, "Rd_tag"), "TEXT"))
4342
stopRd(option, Rdfile, "Bad \\link option -- must be text")
44-
if (grepl("^=", option, perl = TRUE, useBytes = TRUE))
43+
option <- as.character(option)
44+
if (startsWith(option, "="))
4545
dest <- psub1("^=", "", option)
46-
else if (grepl(":", option, perl = TRUE, useBytes = TRUE)) {
46+
else if (grepl(":", option, fixed = TRUE)) {
4747
targetfile <- psub1("^[^:]*:", "", option)
4848
pkg <- psub1(":.*", "", option)
4949
} else {
50+
if (!isTEXT)
51+
stopRd(arg, Rdfile, "Bad \\link[pkg]{topic} -- argument must be text")
5052
targetfile <- dest
51-
pkg <- as.character(option)
53+
pkg <- option
5254
}
53-
}
55+
} else if (!isTEXT)
56+
stopRd(arg, Rdfile, "Bad \\link topic -- must be text")
57+
5458
if (tag == "\\linkS4class") dest <- paste0(dest, "-class")
5559
list(topic = topic, dest = dest, pkg = pkg, targetfile = targetfile)
5660
}

src/library/tools/R/Rd2latex.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,18 @@ Rd2latex <- function(Rd, out = "", defines = .Platform$OS.type,
233233

234234
## Currently ignores [option] except for [=dest] form
235235
## (as documented)
236+
## FIXME: so should not output cross-package links (unless for refman ...)
236237
writeLink <- function(tag, block) {
237-
parts <- get_link(block, tag)
238+
parts <- get_link(block, tag, Rdfile)
238239
if (concordance)
239240
conc$saveSrcref(block)
240-
of0("\\LinkA{", latex_escape_link(parts$topic), "}{",
241+
if (all(RdTags(block) == "TEXT")) {
242+
of0("\\LinkA{", latex_escape_name(parts$topic))
243+
} else { # don't \index link text containing markup etc
244+
of1("\\LinkB{")
245+
writeContent(block, tag)
246+
}
247+
of0("}{",
241248
latex_link_trans0(parts$dest), "}")
242249
}
243250

@@ -290,13 +297,6 @@ Rd2latex <- function(Rd, out = "", defines = .Platform$OS.type,
290297
x
291298
}
292299

293-
latex_escape_link <- function(x)
294-
{
295-
## _ is already escaped
296-
x <- fsub("\\_", "_", x)
297-
latex_escape_name(x)
298-
}
299-
300300
latex_link_trans0 <- function(x)
301301
{
302302
x <- fsub("\\Rdash", ".Rdash.", x)

src/library/tools/man/testInstalledPackage.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ standard_package_names()
6767

6868
\code{testInstalledBasic} runs the basic tests, if installed or inside
6969
\code{testSrcdir}. This
70-
should be run with \code{LC_COLLATE=C} set: the function tries to set
70+
should be run with \link[=LC_COLLATE]{\env{LC_COLLATE}} set to \samp{C}:
71+
the function tries to set
7172
this but it may not work on all OSes. For non-English locales it may
7273
be desirable to set environment variables \env{LANGUAGE} to \samp{en}
7374
and \env{LC_TIME} to \samp{C} to reduce the number of differences from

tests/testit.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ foo(\var{x}, \var{y}, ...)
3434
\code{\%\{\}}
3535

3636
\link{a link} and some to known destinations:
37-
\link[stats]{weighted.mean}, \code{\link[=Paren]{\{}}
37+
\code{\link[stats]{weighted.mean}}, \link[stats:weighted.mean]{dito},
38+
\code{\link[=Paren]{\{}}, \link[=R_HOME]{\env{R_HOME}}.
3839

3940
var in \var{text}.
4041

tests/testit.html.save

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ conditional content.
5555
<p><code>%{}</code>
5656
</p>
5757
<p>a link and some to known destinations:
58-
weighted.mean, <code>{</code>
58+
<code>weighted.mean</code>, dito,
59+
<code>{</code>, <span class="env">R_HOME</span>.
5960
</p>
6061
<p>var in <var>text</var>.
6162
</p>

tests/testit.tex.save

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Escaped backslash \code{\bsl{}x}.
3030
\code{\%\{\}}
3131

3232
\LinkA{a link}{a link} and some to known destinations:
33-
\LinkA{weighted.mean}{weighted.mean}, \code{\LinkA{\{}{Paren}}
33+
\code{\LinkA{weighted.mean}{weighted.mean}}, \LinkA{dito}{dito},
34+
\code{\LinkA{\{}{Paren}}, \LinkB{\env{R\_HOME}}{R.Rul.HOME}.
3435

3536
var in \var{text}.
3637

tests/testit.txt.save

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ _D_e_t_a_i_l_s:
2222

2323
'%{}'
2424

25-
a link and some to known destinations: weighted.mean, '{'
25+
a link and some to known destinations: 'weighted.mean', dito, '{',
26+
'R_HOME'.
2627

2728
var in <text>.
2829

0 commit comments

Comments
 (0)