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{