Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safer latex_dependency insertion #2546

Open
cderv opened this issue Mar 13, 2024 · 2 comments
Open

Safer latex_dependency insertion #2546

cderv opened this issue Mar 13, 2024 · 2 comments

Comments

@cderv
Copy link
Collaborator

cderv commented Mar 13, 2024

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

@yihui
Copy link
Member

yihui commented Mar 13, 2024

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.

@cderv
Copy link
Collaborator Author

cderv commented Mar 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

2 participants