Skip to content

Safer latex_dependency insertion #2546

Open

Description

@cderv

# return the LaTeX dependencies as a string suitable for inclusion
# in the head of a document
latex_dependencies_as_string <- function(dependencies) {
lines <- sapply(dependencies, function(dep) {
opts <- paste(dep$options, collapse = ",")
if (opts != "") opts <- paste0("[", opts, "]")
# \\usepackage[opt1,opt2]{pkgname}
pkg <- paste0("\\usepackage", opts, "{", dep$name, "}")
one_string(c(pkg, dep$extra_lines))
})
one_string(unique(lines))
}

I wonder if it would be ok to use safer inclusion to avoid potential conflict if this is used in a document where the is already loaded package 🤔

Using \@ifpackageloaded{pkgname}{}{\usepackage[options]{name}}

If a package needs options to be set though, there is not really a good way to avoid option conflict, unless this is loaded before documentclass with \PassOptionsToPackage{options}{pkgname}

Anyhow, I feel latex_dependency is not that much used, and if it would be it need to be safer.

For thoughts...

Activity

  1. moved this to To discuss / To plan in R Markdown Team Projectson Mar 13, 2024
  2. yihui commented on Mar 13, 2024

    @yihui
    Collaborator

    Perhaps using \@ifpackageloaded{pkgname} only when opts == ''? That means, if users don't need any options, we can guarantee that the package will be loaded without conflicts. If they do, we just respect the options, which may or may not lead to conflicts.

  3. cderv commented on Mar 13, 2024

    @cderv
    CollaboratorAuthor

    Yes definitely - \@ifpackageloaded{pkgname} should be only used if opts == ''. I like that. thanks !

  4. moved this from To discuss / To plan to Backlog in R Markdown Team Projectson Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions