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

Allow use of a function for fig, eq or tab labels #1120

Merged
merged 13 commits into from
Apr 1, 2021
Merged

Allow use of a function for fig, eq or tab labels #1120

merged 13 commits into from
Apr 1, 2021

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Mar 31, 2021

This will solves #1114

For now I only added support for fig, eq and tab. Support for theorem or proof env is a bit trickier because label_prefix is used for find the label to use for \newtheorem in preamble where number is not used

str_trim(vapply(theorem_abbr, label_prefix, character(1), USE.NAMES = FALSE)),

and for proof env too
gsub('^\\s+|[.]\\s*$', '', vapply(proof_envs, label_prefix, character(1), label_names_math2))

This means it can't be a function of reference number, and case is different between LaTeX and non LaTeX.
I wanted to support all because for non LaTeX output this is the same mechanism: label is prepended by default. However, I did not find an easy way to do it because of the constraint mention above. But also I am not sure that what I have done currently is a lot easier.

@yihui you may want to review that more closely in case you see a way to also allow the use of a function for all theorem_abbr and label_names_math2.

if (type %in% names(theorem_abbr)) {
if (type %in% theorem_abbr) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not part of the feature request but I think it was not working as expected before, and the span was never inserted. So I fixed it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks for catching it!

Copy link
Member

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is much more common for users to customize figure and table names. We can consider theorems in the future if someone asks for the feature. Thanks!

if (type %in% names(theorem_abbr)) {
if (type %in% theorem_abbr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks for catching it!

R/latex.R Outdated Show resolved Hide resolved
@cderv cderv merged commit 1335d66 into master Apr 1, 2021
@cderv cderv deleted the i18n-fct branch April 1, 2021 12:51
yihui added a commit that referenced this pull request Apr 1, 2021
@tamas-ferenci
Copy link

Thank you! Unfortunately theorem is the same story in Hungarian (Theorem 1 should be 1. tétel), but it is of course needed much-much less often than figure or table, and I am personally fine now. Thank you again!

@cderv
Copy link
Collaborator Author

cderv commented Apr 3, 2021

Yes theorem was trickier to support.
Do you change it already for pdf using LaTeX in preamble ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] internationalization - Customize figure names to set label after number
3 participants