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

Customize font size and font family for STEM expressions #45

Open
qtran-n4 opened this issue Jan 3, 2019 · 13 comments
Open

Customize font size and font family for STEM expressions #45

qtran-n4 opened this issue Jan 3, 2019 · 13 comments

Comments

@qtran-n4
Copy link

qtran-n4 commented Jan 3, 2019

Hi guys,

I have two questions/issues:

  1. How can I configure the font size of a STEM expression?
    In the screenshot, I am rendering the PDF using asciidoctor-pdf. Also, I customized base.font_size= 15 in a custom theme. As we can see, the size of the text is 15 and is much bigger than the size of the STEM expression.

How can I configure the font size of a STEM expression?

  1. Is it possible to configure the font used for rendering STEM expressions?
    The font used in the STEM expression is different from the font for text. How can I configure the font family for STEM expressions?

Thanks a lot!

Screenshot below:

screen shot 2019-01-03 at 14 25 41

@qtran-n4 qtran-n4 changed the title Customize Customize font size and font family for STEM expressions Jan 3, 2019
@ProgramFan
Copy link
Contributor

As far as I know, mathematical converts fonts into paths in the resultant svg file. So it is impossible to change the font without help from mathematical, which does not provide such support yet.

For the STEM size, it is possible to let asciidoctor-pdf scale the image to the same height as the surrounding lines?

@qtran-n4
Copy link
Author

qtran-n4 commented Jan 3, 2019

@ProgramFan Thanks a lot for your quick response! I am more interested in configuring the font size right now. I am trying to do exactly what you said in asciidoctor-pdf: trying to scale image to the line height

Unfortunately, I haven't found a way yet...

@ProgramFan
Copy link
Contributor

I do not use asciidoctor-pdf often so you'd better refer to @mojavelinux.

@qtran-n4
Copy link
Author

qtran-n4 commented Jan 3, 2019

@mojavelinux Hey Dan, do you have any hint how I can achieve this? Thanks!

@mojavelinux
Copy link
Member

If my understanding is correct, asciidoctor-mathemetical produces an SVG which is embedded into the PDF. If that's the case, then you'll need to set the dimensions of the SVG to match the line height. See https://github.com/asciidoctor/asciidoctor-pdf/blob/master/README.adoc#image-scaling

I'll do a quick test to see if I can figure out what setting to use.

@mojavelinux
Copy link
Member

(I didn't mean to close the issue. I accidentally hit the button trying to focus the text area).

@mojavelinux
Copy link
Member

In short, you'd need to influence the dimensions of the image macro that asciidoctor-mathematical produces. Unfortunately, there's no way to express height=1em (or pdfheight=1em) in Asciidoctor PDF currently. The only dimension you can control is width (which would depend on the length of the equation). So we'd first need to add support for controlling the height of an image in Asciidoctor PDF. Then asciidoctor-mathematical could output that preference.

I suppose in the meantime, asciidoctor-mathematical could support some sort of scale factor so you can size all images up by a certain amount. That would certainly address the issue in the short-term.

@mojavelinux
Copy link
Member

Perhaps something like mathematical-scale? It would need to scale the width and height proportionally (or just not set the height, since the height of an image is never used in Asciidoctor).

@ProgramFan
Copy link
Contributor

Are there any ways to scale an image in asciidoctor-pdf so that the image height is identical to the line height? If possible, asciidoctor can export special attributes to the image macro, and asciidoctor-mathematical can make use of it. This approach can also solve the height-mismatches when using equations in titles.

@mojavelinux
Copy link
Member

As I mentioned, we would need a change to Asciidoctor PDF.

@qtran-n4
Copy link
Author

qtran-n4 commented Jan 14, 2019

Thanks a lot again for your replies @mojavelinux and @ProgramFan! I tried to go over the route: asciidoc -> docbook -> dblatex and had lots of success. The math generated by the Latex toolchain looks great. If there is any improvement in asciidoctor-mathematical, I will try it again in the future.

@bwittman
Copy link
Contributor

Perhaps something like mathematical-scale? It would need to scale the width and height proportionally (or just not set the height, since the height of an image is never used in Asciidoctor).

I hacked a scale factor into my local copy of asciidoctor-mathematical and used it with asciidoctor-pdf. It looks much better, but the baseline of the image is still wrong, giving the appearance that the equation is floating in the air. I haven't done any hacking on asciidoctor-pdf. Does anyone have any insights about where in its codebase the changes would need to go so that it passed enough information to asciidoctor-mathematical?

Or does anyone know who works on asciidoctor-pdf who might be interested in helping with this problem? I'm surprised more people aren't bothered by this problem, since weak LaTeX support seems to be a significant drawback of the PDF backend relative to the HTML backend.

@mojavelinux
Copy link
Member

Does anyone have any insights about where in its codebase the changes would need to go so that it passed enough information to asciidoctor-mathematical?

There isn't a direct integration between Asciidoctor PDF and asciidoctor-mathematical. asciidoctor-mathematical produces an SVG, which Asciidoctor PDF then embeds. But Asciidoctor PDF doesn't even really handle that either. That's the job of prawn-svg. So you might want to try the generated SVG with prawn-svg first to see if that's working. If that works, but it doesn't work in Asciidoctor PDF, then we can look deeper. At that point, I would encourage you to open an issue in Asciidoctor PDF.

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

No branches or pull requests

4 participants