asciidoctor / asciidoctor-mathematical

An extension for Asciidoctor that converts the content of STEM blocks and inline macros using Mathematical.
MIT License
49 stars 44 forks source link

Customize font size and font family for STEM expressions #45

Open qtran-n4 opened 5 years ago

qtran-n4 commented 5 years ago

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?

2) 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
ProgramFan commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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

qtran-n4 commented 5 years ago

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

mojavelinux commented 5 years ago

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 commented 5 years ago

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

mojavelinux commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

qtran-n4 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.