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

vertical alignment for images #907

Merged
merged 2 commits into from
Aug 20, 2023
Merged

Conversation

Alex-Jordan
Copy link
Contributor

@Alex-Jordan Alex-Jordan commented Aug 13, 2023

This lets you declare vertical alignment for an image relative to the baseline of any surrounding text surrounding line of text. Note that right now, an image within text will be middle-aligned in HTML output and bottom-aligned in hardcopy, so there is already an inconsistency there. This changes the default to be "middle", so changing the behavior with hardcopy but not changing it with HTML.

To test, take your favorite image as $image and run the following. Make sure to look at HTML and hardcopy.

BEGIN_PGML
Top top top top top top top top top top top top top top top top top top top top top top [! alt text !]{$image}{image_options => {valign => 'top'}} top top top top top top top top top top top top top top top top top top top top

Middle middle middle middle middle middle middle middle middle middle middle middle middle [! alt text !]{$image}{image_options => {valign => 'middle'}} middle middle middle middle middle middle middle middle middle middle middle 

Bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom [! alt text !]{$image}{image_options => {valign => 'bottom'}}  bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom
END_PGML

BEGIN_TEXT
Top top top top top top top top top top top top top top top top top top top top top top \{image($image, valign => 'top')\} top top top top top top top top top top top top top top top top top top top top

Middle middle middle middle middle middle middle middle middle middle middle middle middle \{image($image, valign => 'middle')\} middle middle middle middle middle middle middle middle middle middle middle middle middle middle 

Bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom \{image($image, valign => 'bottom')\} bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom bottom
END_TEXT

@Alex-Jordan Alex-Jordan force-pushed the image-valign branch 2 times, most recently from 4c2d1c7 to f61294f Compare August 13, 2023 04:05
Comment on lines 3058 to 3063
"\\raisebox{-\\height + \\fontcharht\\font`I}{\\includegraphics[width=$width_ratio\\linewidth]{$imagePath}}\n";
} elsif ($valign eq 'bottom') {
$out = "\\includegraphics[width=$width_ratio\\linewidth]{$imagePath}\n";
} else {
$out =
"\\raisebox{-0.5\\height + 0.5\\fontcharht\\font`I}{\\includegraphics[width=$width_ratio\\linewidth]{$imagePath}}\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backticks here are causing a problem in BEGIN_TEXT/END_TEXT blocks. This is passed through EV3P and then EV3P_parser in that case, and backticks have special meaning. This results in the following text being passed through the Parser, and this gives "Error: Variable 'I' is not defined in this context; see position 1 of formula 'I" in the output. Then there is an error when LaTeX runs on that. This occurs with your MWE.

@Alex-Jordan
Copy link
Contributor Author

Alex-Jordan commented Aug 17, 2023 via email

@drgrice1
Copy link
Member

You could define this length in the pg.sty file. In that file add

\newlength{\imageskipheight}
\AtBeginDocument{\setlength{\imageskipheight}{\fontcharht\font`I}}

That won't be parsed by PG at all, and so it avoids this issue.

@Alex-Jordan
Copy link
Contributor Author

I declared a length in pg.sty like you suggested, but am setting it locally where it is used. I'm not entirely sure that this couldn't come up in a block of text that is, for example, \small text. And then the height should be relative to that local font.

And now it's using \settoheight. As long as there is already a new height unit declared, that removes the need I perceived before for the backtick construction.

@drgrice1
Copy link
Member

I will merge this since the hotfix of this was merged.

@drgrice1 drgrice1 merged commit 4245b61 into openwebwork:develop Aug 20, 2023
2 checks passed
@drgrice1
Copy link
Member

Oops. This wasn't one that was in the hotfix list. Oh, well. It was ready. I just hadn't put my approval on. @pstaabp did.

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

Successfully merging this pull request may close these issues.

3 participants