I am using Hugo for Scientific writing.
Hence it is important for me to be able to number and then cross reference to figures in the post.
Using counters I’m able to automatically add numbers to my Figure elements.
Now I’m after being able to cross reference them in the post.
So I have few questions:
- Could I have some way to add an ID to the figure elements? It seems the built in shortcode, for some reason, doesn’t expose such option. Here I assume I will be able to easily link to tags in the MarkDown text.
- In case there is no simple way to add an ID to the figure element, Is there another way you’d recommend?
Hey! Yes, it’s possible! The way to do it would be:
- Add your own copy of
themes/[your-theme]/shortcodes/figure.html. Hugo will use this one instead of the standard one.
- Copy in the code for the default figure shortcode
- Modify it to accept and set an ID parameter.
If you want to number them automatically from Hugo instead of doing it in CSS, that’s possible too! From the shortcode, you can store values in
.Page.Scratch, and then increment a stored value every time the shortcode gets used.
I’ve used both of these techniques before, but I’m also writing this from the top of my head, so they might need to be checked / adjusted
Do you think it is reasonable to open GitHub issue with asking adding the
ID option to the official figure template?