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

[FR] internationalization - Customize figure names to set label after number #1114

Closed
tamas-ferenci opened this issue Mar 30, 2021 · 11 comments · Fixed by #1120
Closed

[FR] internationalization - Customize figure names to set label after number #1114

tamas-ferenci opened this issue Mar 30, 2021 · 11 comments · Fixed by #1120
Assignees
Labels
feature a feature request or enhancement next to consider for next release

Comments

@tamas-ferenci
Copy link

(Already posted in Stackoverflow here to no avail.)

Bookdown allows the customization of chapter names, which is handy when a Hungarian project is built, as Chapter 1 is translated as 1. fejezet (i.e. the renaming of Chapter is not enough).

However, the very same is true for figure (and table) names as well, because Figure 1.1 should be translated as 1.1. ábra, but I don't know how to achieve this (_bookdown.yml doesn't seem to support something like "language/ui/figure_name" just as it does with chapter_name).

There is no problem with the PDF (LaTeX) output, because including \usepackage[magyar]{babel} in the preamble.tex solves this problem, but I don't know what to do with the non-PDF formats, where my only idea was to use the _bookdown.yml.

@cderv
Copy link
Collaborator

cderv commented Mar 30, 2021

In the doc you linked to: https://bookdown.org/yihui/bookdown/internationalization.html it is explain with an example how to change a the figure label name, using the language and label key in the YAML

What is not working for you with this ?

@tamas-ferenci
Copy link
Author

Because the translation of Figure should go after the number, not before it (as I have written: "Figure 1.1 should be translated as 1.1. ábra") and this is not possible with the possibilities listed in that doc, where I can only change the text, but I can't put it after the number in my understanding.

@cderv
Copy link
Collaborator

cderv commented Mar 30, 2021

That is right, this is currently not possible to do that. Thanks for explaining.

It will always be <fig_lab>: <number> for now.

Out of curiosity, in which language do you label figure this way ?

@cderv cderv added the feature a feature request or enhancement label Mar 30, 2021
@cderv cderv changed the title [FR] Possibility to customize figure names similar to chapter names [FR] internationalization - Customize figure names to set label after number Mar 30, 2021
@tamas-ferenci
Copy link
Author

It's Hungarian. The reason why I hope for a possible new feature to support this is that the exact same thing is already working for chapter name! The cited doc even gives an example for this. The very same solution would be perfect for figure (and table) names.

@cderv
Copy link
Collaborator

cderv commented Mar 30, 2021

You mean the use of a function taking chapter number as argument ? Is that what you use for chapter name ?

@tamas-ferenci
Copy link
Author

Yes, Chapter 1 is translated as 1. fejezet. The solution is therefore simply:

language:
  ui:
    chapter_name: !expr function(i) paste0(i, ". fejezet")

A similar solution would be perfect for figure and table naming.

@yihui
Copy link
Member

yihui commented Mar 30, 2021

That sounds like a reasonable feature request to me.

@tamas-ferenci
Copy link
Author

Thanks @yihui ! Together with #671 it'd make bookdown very nicely working for Hungarian as well :)

@cderv cderv added the next to consider for next release label Mar 31, 2021
@cderv cderv self-assigned this Mar 31, 2021
@cderv
Copy link
Collaborator

cderv commented Mar 31, 2021

@tamas-ferenci you may try #1120

remotes::install_github("rstudio/bookdown#1120")

where this should work now

language:
  label:
    fig: !expr function(i) paste(i, 'ábra')
  ui:
    chapter_name: !expr function(i) paste0(i, '. fejezet')

@cderv cderv closed this as completed Apr 1, 2021
@cderv cderv linked a pull request Apr 1, 2021 that will close this issue
@tamas-ferenci
Copy link
Author

Thank you very much @cderv and @yihui ! I checked it, and it indeed seems to work fine! I only see two (very minor) problems:

  • The documentation says fig: !expr function(i) paste(i, 'ábra') which is technically correct, but the Hungarian typography would imply fig: !expr function(i) paste0(i, '. ábra.').
  • There is no space between the end of the text inserted and the first letter of the figure caption:
    kép
    That's not a huge problem as one could easily circumvent it with fig: !expr function(i) paste(i, '. ábra. '), but this was not needed for chapter_name (where even !expr function(i) paste0(i, '. fejezet') results in a space after fejezet and before the chapter name), so the two are not perfectly consistent right now.

@github-actions
Copy link

github-actions bot commented Oct 6, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement next to consider for next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants