diff --git a/DESCRIPTION b/DESCRIPTION index ff2d986f..9760e2a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,6 +20,7 @@ URL: https://hughjonesd.github.io/huxtable/ BugReports: https://github.com/hughjonesd/huxtable/issues Imports: assertthat, + base64enc, commonmark, fansi, generics, @@ -81,7 +82,7 @@ SystemRequirements: LaTeX packages: VignetteBuilder: knitr Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) Depends: R (>= 2.10) diff --git a/R/aaa-utils.R b/R/aaa-utils.R index 450512d3..398ae126 100644 --- a/R/aaa-utils.R +++ b/R/aaa-utils.R @@ -224,10 +224,9 @@ make_label <- function (ht) { } if (! is.null(chunk_label) && - are_we_in_quarto() && - requireNamespace("quarto", quietly = TRUE) && - quarto::quarto_version() >= "1.4" && - getOption("huxtable.knitr_output_format", guess_knitr_output_format()) == "latex" + using_quarto("1.4") && + getOption("huxtable.knitr_output_format", + guess_knitr_output_format()) == "latex" ) { msg <- paste( "quarto cell labels do not work with huxtable in TeX for quarto ", @@ -246,9 +245,15 @@ make_label <- function (ht) { } -are_we_in_quarto <- function () { - requireNamespace("knitr", quietly = TRUE) && - ! is.null(knitr::opts_knit$get("quarto.version")) +using_quarto <- function (min_version = NULL) { + if (! requireNamespace("knitr", quietly = TRUE)) return(FALSE) + if (is.null(knitr::opts_knit$get("quarto.version"))) return(FALSE) + if (is.null(min_version)) return(TRUE) + + # this is risky since they could have quarto without the R package + if (! requireNamespace("quarto")) return(FALSE) + qv <- quarto::quarto_version() + return(qv >= min_version) } diff --git a/R/latex.R b/R/latex.R index 2e903ab6..436e598d 100644 --- a/R/latex.R +++ b/R/latex.R @@ -141,6 +141,12 @@ build_latex_caption <- function (ht, lab) { lab <- if (is.na(lab) || cap_has_label) "" else sprintf("\\label{%s}\n", lab) cap <- paste(cap, lab) + if (using_quarto(min_version = "1.4") && + getOption("huxtable.knitr_output_format", + guess_knitr_output_format()) == "latex") { + cap <- sprintf("\\QuartoMarkdownBase64{%s}", + base64enc::base64encode(charToRaw(cap))) + } return(cap) } diff --git a/R/package-docs.R b/R/package-docs.R index 6294070e..230f37b2 100644 --- a/R/package-docs.R +++ b/R/package-docs.R @@ -215,20 +215,18 @@ NULL #' like `label: tbl-foo` and refer to them via `@tbl-foo`. #' #' In quarto versions 1.4 and above, when compiling to PDF, -#' quarto cross-referencing no longer works, and labels starting with -#' `tbl-` will cause an error. (This is a quarto -#' issue.) Instead, set labels within huxtable using [label()] or +#' quarto cross-referencing no longer works. +#' Instead, set labels within huxtable using [label()] or #' [set_label()] and refer to them with TeX-only referencing using -#' `\ref{label}`. You must also set a caption, either via quarto or via -#' huxtable. +#' `\ref{label}`. You must also set a caption. #' #' Here's an example: #' #' ```` -#' A reference to Table \ref{tab:jams}. +#' A reference to Table \ref{tbl-jams}. #' #' ```{r} -#' label(jams) <- "tab:jams" +#' label(jams) <- "tbl-jams" #' caption(jams) <- "Some jams" #' jams #' ``` diff --git a/man/huxtable-FAQ.Rd b/man/huxtable-FAQ.Rd index 6ac30851..f3d41c93 100644 --- a/man/huxtable-FAQ.Rd +++ b/man/huxtable-FAQ.Rd @@ -82,19 +82,17 @@ other formats, simply use quarto cell labels like \code{label: tbl-foo} and refer to them via \verb{@tbl-foo}. In quarto versions 1.4 and above, when compiling to PDF, -quarto cross-referencing no longer works, and labels starting with -\verb{tbl-} will cause an error. (This is a quarto -issue.) Instead, set labels within huxtable using \code{\link[=label]{label()}} or +quarto cross-referencing no longer works. +Instead, set labels within huxtable using \code{\link[=label]{label()}} or \code{\link[=set_label]{set_label()}} and refer to them with TeX-only referencing using -\verb{\\ref\{label\}}. You must also set a caption, either via quarto or via -huxtable. +\verb{\\ref\{label\}}. You must also set a caption. Here's an example: -\if{html}{\out{
}}\preformatted{A reference to Table \\ref\{tab:jams\}. +\if{html}{\out{
}}\preformatted{A reference to Table \\ref\{tbl-jams\}. ```\{r\} -label(jams) <- "tab:jams" +label(jams) <- "tbl-jams" caption(jams) <- "Some jams" jams ``` @@ -141,3 +139,15 @@ I'd rather you asked on a public website. If you then email me a link, I may be able to help. } } +\seealso{ +Useful links: +\itemize{ + \item \url{https://hughjonesd.github.io/huxtable/} + \item Report bugs at \url{https://github.com/hughjonesd/huxtable/issues} +} + +} +\author{ +\strong{Maintainer}: David Hugh-Jones \email{davidhughjones@gmail.com} + +} diff --git a/scripts/quarto-test.qmd b/scripts/quarto-test.qmd index dc964f8c..43d71896 100644 --- a/scripts/quarto-test.qmd +++ b/scripts/quarto-test.qmd @@ -1,18 +1,25 @@ --- title: "Quarto tester" -format: pdf +format: + pdf: + keep-tex: true +html-table-processing: none --- +Quarto version: `r quarto::quarto_version()`. -Reference to @tbl-jams +# Builtin huxtable labels/captions ```{r} -#| tbl-cap: quarto cap -#| label: tbl-jams library(huxtable) -caption(jams) <- "huxtable caption" +caption(jams) <- "Table of jams" +label(jams) <- "tbl-jams" jams +# 1.5.45 +# You need to enclose caption and label in \QuartoMarkdownBase64{}. +# Then you can use any label, although Quarto processing still won't work. + # 1.4.549 # works with no label/caption at all # works with only quarto caption, only huxtable caption, or both: @@ -25,4 +32,19 @@ jams # works with quarto caption and label, so long as label is not tbl- ``` -Post-reference to \ref{jams}. +Quarto reference to @tbl-jams. +LaTeX reference to \ref{tbl-jams}. + +# Quarto labels/captions + +```{r} +#| label: tbljams2 +#| tbl-cap: Table of Jams 2 + +data(jams) # clean version +jams +``` + +Quarto reference to @tbljams2. +LaTeX reference to \ref{tbljams2}. +