1

I often need to change dynamically the font size or other properties for xaringan slides. Instead of defining a lot of different CSS classes I would like to define a general fontsize class and then passing a % value as variable. Something like this https://stackoverflow.com/a/17894116/9032257:

# Header 1

.fontsize50[
- some text
- some text
]

But fontisize50 is not hard coded on the CSS file. Is that possible?

Update

I have tried to use the approach proposed on Remark documentation https://github.com/gnab/remark/issues/72#issuecomment-62225566. I am able to dynamically the font size of a single word but not applying the font-size property to an entire section.

Adding this function to a macro.js file and setting the beforeInit YAML:

remark.macros.fontsize = function (size = "100%") {
  var txt = this;
  tag = "<span style=" + "'font-size:" + size + "'>" + txt + "</span>";
  return tag
};

Then using this:

# Header 1

<!-- This Works -->

Hello ![:fontsize 200%](World)!

<!-- This Not -->

Hello ![:fontsize 200%](

- bullet 1
- bullet 2
- bullet 3

)

Change the fontsize according to the percentage only in the first case. I would like to have the same behavior as having a CSS class:

.font50 {
   font-size: 50%;
}

And then using:

Hello

.font50[

- bullet 1
- bullet 2
- bullet 3

]

But I am not able to do this.

2
  • 1
    I'm afraid it's not possible. This is essentially the same issue as github.com/yihui/xaringan/issues/360. Commented Nov 1, 2022 at 20:33
  • 1
    Thank you @YihuiXie. I have tried to use this approach github.com/gnab/remark/issues/72#issuecomment-62225566 but I am able to only change a single word or a piece of text but not adding a CSS class to an entire section as using .[]. I'll update my question maybe it is useful to someone Commented Nov 2, 2022 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.