Skip to content

Safer latex_dependency insertion #2546

@cderv

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions