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

Difficulties vertically aligning inline latexmath #1483

Open
davidplowman opened this issue Jan 9, 2020 · 21 comments
Open

Difficulties vertically aligning inline latexmath #1483

davidplowman opened this issue Jan 9, 2020 · 21 comments
Milestone

Comments

@davidplowman
Copy link

Hi, I was advised in the asciidoctor-mathematical issues list to post this report here.

I have made a very simple example, consisting of a file with a single line.

An inline equation latexmath:[w] and bigger latexmath:[{\large w}]. With subscripts latexmath:[w_{ij}] bigger latexmath:[{\large w_{ij}}]. (As plain text, not an equation, we get _w~ij~_)

and turn it into a pdf using

asciidoctor-pdf -r asciidoctor-mathematical -o test.pdf test.adoc

My problem is that the inline equations (whether using png or svg mode) don't sit on the line with the other text - and it gets worse when there are subscripts. Does anyone know of any techniques to work around this situation?

Here's a screenshoot of how it looks:
screenshot

@mojavelinux
Copy link
Member

Asciidoctor PDF is centering the image on the line (emulating vertical-align: middle). There's currently no way to control the vertical alignment of inline images in Asciidoctor PDF. We could consider adding that as a feature. What you seem to be after is vertical-align: text-bottom).

@mojavelinux
Copy link
Member

mojavelinux commented Jan 9, 2020

and it gets worse when there are subscripts

To a certain degree, this is just the way those are going to be (once the image can be aligned to text-bottom). Asciidoctor PDF doesn't see text with subscript. It just sees an image. So the bottom of the image, no matter where it is, would align with the bottom of the text. That's just a limitation of this integration approach.

@mojavelinux mojavelinux added this to the v2.0.0 milestone Jan 9, 2020
@davidplowman
Copy link
Author

Yes, I can see that for each embedded image you'd have to know the vertical coordinate of where the base of the text is supposed to be. Tricky! But thanks for the feedback.

@mojavelinux
Copy link
Member

One thing I would recommend for asciidoctor-mathematical is to allow the image to be scaled by a fixed amount. That would allow the image to take up more of the line and thus align better with the existing text. I'm not sure how it determines the sizes now, but if they aren't adjustable, that itself can be problematic.

@ProgramFan
Copy link

I would like to add logic in asciidoctor-mathematical for a better inline equation layout. The feature I would like to have from asciidoctor-pdf, maybe from asciidoctor for inline images in general, is like the following:

  1. allow setting image height to something like: X line-height, where x is a floating-point number such as 1.0.
  2. allow adjusting the way inline images vertically align with the line, maybe something like 'center, bottom, top'.

This feature can only be provided as an extension to the inline image macro at the moment since inline markups are not part of the AST.

@ProgramFan
Copy link

ProgramFan commented Jan 10, 2020

In fact, I once tried to make the equations scale with the text, to make them the same size as the texts in titles, but without any successes. So at the moment, the equations in titles look extremely ugly since they are too small. The same happens in asciidoctor and asciidoctor-pdf.

@mojavelinux
Copy link
Member

In the current version of Asciidoctor PDF, it's possible to make the image fit to the height of the line using fit=line. However, this includes the line spacing, so the image ends up being taller than the text.

I agree we can consider having control over the vertical alignment. Like I said, what you probably want is baseline so that the image lines up with the bottom of the text. (It already does center, and top and bottom would be above and below the text, respectively).

There are, however, limits to how much this can even work. Prawn doesn't really have the same concept of lines like HTML/CSS. So we can fake it to a point, but then it gets really fuzzy.

@mojavelinux
Copy link
Member

mojavelinux commented May 2, 2020

There are actually two problems here. First is the vertical alignment of the image. Second is that there doesn't seem to be any way to influence the height of the inline image that Asciidoctor Mathematical generates. It only bases the size on ppi for PNG and zoom for SVG. That's where the fit=line option (or similar) might help...because it allows Asciidoctor PDF to adjust the size of the image.

Perhaps we need fit=line and fit=font-size depending on whether you want to fit the image to the line height or height of text (capital letter).

I once tried to make the equations scale with the text, to make them the same size as the texts in titles, but without any successes.

I don't think Asciidoctor Mathematical should manipulate the height and width itself (aside from the global scaling). It should be reporting the intrinsic height and width, but also include a role or option that allows the converter (or browser) to make the final adjustment.

@mojavelinux
Copy link
Member

I'm starting to think a role might be best so that the HTML converter can control the size with CSS.

@ProgramFan Would you also consider adding support for the mathematical-zoom attribute to control the base zoom for SVG images?

@ProgramFan
Copy link

I can add the mathematical-zoom attribute, but how shall it be defined?

@mojavelinux
Copy link
Member

I would just allow the user to define mathematical-zoom, convert it to a double, and pass it through to Mathematical using the zoom option.

@ProgramFan
Copy link

ProgramFan commented May 4, 2020

I don't quite understand the idea. Here is my confusion: asciidoctor-mathematical works as a tree-preprocessor and just replaces the stem macros with image macros, so it generates the images prior to asciidoctor-pdf. But the zoom value can only be determined in asciidoctor-pdf and can be different under different scenarios (for example in titles and paragraphs). How can asciidoctor-mathematical act on a value that is not defined?

My first imagnation of a solution is that the backends act on things like height=1em. And asciidoctor-mathematical just set these attributes on the images it generates. But this is just my own opinion.

@mojavelinux
Copy link
Member

mojavelinux commented May 4, 2020

My first imagnation of a solution is that the backends act on things like height=1em.

Yes, I get that. But for environments for where that doesn't apply or it can't work, the zoom would be a way to influence the intrinsic size that mathematical produces. It's a global setting, defined by the mathematical-zoom attribute and passed to the Mathematical constructor. (It has nothing at all to do with the backend in use).

Regardless, we can't use height=1em as that's not a valid value for height. But we could use an attribute like fit=1em or a role like .fit-content or something.

@ProgramFan
Copy link

I see. I will add mathematical-zoom just like that.

@mojavelinux
Copy link
Member

👍

We'll then continue this discussion about how to coordinate so that the converter can resize the equation to fit with the size of the text.

@mcp292
Copy link

mcp292 commented Sep 2, 2020

Has any progress been made on this front?

@mojavelinux
Copy link
Member

If there were progress, it would be reported here.

@mcp292
Copy link

mcp292 commented Sep 3, 2020

Oh, got it!

@graphitefriction graphitefriction modified the milestones: v2.0.0, v2.1.x Apr 25, 2022
@mojavelinux mojavelinux modified the milestones: v2.1.x, v2.2.x Jun 21, 2022
@mojavelinux mojavelinux modified the milestones: v2.2.x, v2.3.x Jul 22, 2022
@mojavelinux mojavelinux modified the milestones: v2.3.x, v3.0.x Aug 16, 2022
@mojavelinux
Copy link
Member

Related to asciidoctor/asciidoctor-mathematical#45.

@aburkov
Copy link

aburkov commented May 3, 2024

Hi! Is there a version of asciidoctor where the inline math characters are aligned with the text in the PDF output? If not, is there a way to tweak this somehow?

@mojavelinux
Copy link
Member

The current state is reflected by this issue and the linked one. If there was a change, this issue would be updated or closed.

If you need help with a workaround, please ask in the project chat at https://chat.asciidoctor.org. Someone there may be able to help you.

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

No branches or pull requests

6 participants