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

let width specifications in niceTables be numbers from (0,1] #1088

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

Alex-Jordan
Copy link
Contributor

niceTables allows width specification for columns or cells using the LaTeX column type p{width}. With this PR, width can now be a decimal from 0 (exclusive) to 1 (inclusive). This is understood to be a portion of the available width.

  • In HTML, something like 40% should appear in CSS.
  • In TeX, something like 0.4\linewidth should appear in appropriate places.
  • In PTX, something like 40% should appear in either
    • a col's width attribute (for a DataTable)
    • or an sbsgroup's widths attribute (for a LayoutTable).

Note that PTX has no way to specify a width for an individual cell.

You can try with this test file:

DOCUMENT();

loadMacros(qw(PGstandard.pl PGML.pl PGcourse.pl));

BEGIN_PGML

[#
	[. This table should have a 40% width column, an unspecified column, and a 1-inch column. .]
	[. This table should have a 40% width column, an unspecified column, and a 1-inch column. .]
	[. This table should have a 40% width column, an unspecified column, and a 1-inch column. .]
#]{padding => [0,1], align => 'p{0.4}lp{1in}'}

----

[#
	[. This table should have a 40% width cell, an unspecified cell, and a 1-inch column. .]{halign => 'p{0.4}'}
	[. This table should have a 40% width cell, an unspecified cell, and a 1-inch column. .]
	[. This table should have a 40% width cell, an unspecified cell, and a 1-inch column. .]{halign => 'p{1in}'}
#]{padding => [0,1]}

----

[#
	[. This table should have a 40% width column, an unspecified column, and a 1-inch column. And then overrided by a 50% cell, a 1in cell, and a 20% cell .]{halign => 'p{0.5}'}
	[. This table should have a 40% width column, an unspecified column, and a 1-inch column. And then overrided by a 50% cell, a 1in cell, and a 20% cell .]{halign => 'p{1in}'}
	[. This table should have a 40% width column, an unspecified column, and a 1-inch column. And then overrided by a 50% cell, a 1in cell, and a 20% cell .]{halign => 'p{0.2}'}
#]{padding => [0,1], align => 'p{0.4}lp{1in}', center => 0}

----
# Layout Table

[#
	[. This table should have a 40% width column, an unspecified column, and a 30% column. .]
	[. This table should have a 40% width column, an unspecified column, and a 30% column. .]
	[. This table should have a 40% width column, an unspecified column, and a 30% column. .]
#]*{padding => [0,1], align => 'p{0.4}lp{0.3}', center => 0}

END_PGML

ENDDOCUMENT();

@Alex-Jordan
Copy link
Contributor Author

To test this, you should load a problem (perhaps the one posted here) in the editor. And then examine the output for MathJax, TeX, and PTX. With the latter two, you can see directly where the width specifications are. With MathJax, you can use the inspector to make sure things are what they are supposed to be.

@drgrice1
Copy link
Sponsor Member

The last case in your example (the layout table) does not seem to be working. I see that the style for the first cell has "width: 0.4". 0.4 is an invalid value for width.

@Alex-Jordan
Copy link
Contributor Author

Hmm, I see it as 40%.

Screenshot 2024-07-25 at 8 21 37 AM

This was the last things I fixed. So I thought for a second maybe I hadn't pushed this, but the commit hash here is b23bc05 and that matches what I have. Since this was the last thing, is there any chance you have the previous version before my last force push late last night?

@drgrice1
Copy link
Sponsor Member

Heh! It seems I just tested your sample problem with the PG-2.19 branch, and forgot to even check out your branch. That was dumb.

Copy link
Sponsor Member

@drgrice1 drgrice1 left a comment

Choose a reason for hiding this comment

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

Looks good. Everything seems to work as claimed.

@Alex-Jordan
Copy link
Contributor Author

I changed one more thing here that will only affect PTX output. First, I reviewed the actual definitions of lengths in TeX, and redefined the conversion from one unit to another based on those actual TeX definitions. And the conversion is all to pt instead of cm, since that is the more fundamental unit in TeX.

And that is also good because the default line with for a PTX document is 340pt. So it helps clarify how to translate an absolute width (which PTX disallows) to a percent width.

@pstaabp pstaabp merged commit 63b9382 into openwebwork:PG-2.19 Aug 6, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

3 participants