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

Width of table containing math is based on width of LaTeX commands #6254

Closed
Dr-Irv opened this issue Apr 6, 2020 · 10 comments
Closed

Width of table containing math is based on width of LaTeX commands #6254

Dr-Irv opened this issue Apr 6, 2020 · 10 comments

Comments

@Dr-Irv
Copy link

Dr-Irv commented Apr 6, 2020

When creating a table in markdown and the table has math in the cells, and then converting to PDF, the width of the table is influenced by the length of the LaTeX commands that create the math.

Here's markdown text for 2 tables. The first one is using \mathcal around some of the letters, while the second one doesn't. When rendered, the tables should be of the same width.

# Test

This is test of math in a table.

| a | b | c |
|---|---|---|
| $n_b$ | $\tau^u$ | $\vert\bar{\mathcal B}\vert$ |
| $q_{pb}$ | $\vert\mathcal P\vert\times\vert\mathcal B\vert$ | $\sum_{b\in\bar{\mathcal B}}\vert\bar{\mathcal P}_b\vert$ |

End of table.

| a | b | c |
|---|---|---|
| $n_b$ | $\tau^u$ | $\vert\bar B\vert$ |
| $q_{pb}$ | $\vert P\vert\times\vert B\vert$ | $\sum_{b\in\bar B}\vert\bar P_b\vert$ |

End of second table.

Here is a pic of the output:

image

Version Info:

pandoc 2.2.3.2                                                              
Compiled with pandoc-types 1.17.5.1, texmath 0.11.0.1, skylighting 0.7.2    
@jgm
Copy link
Owner

jgm commented Apr 6, 2020

Actually it depends on the separator lines, not the content. See the manual under pipe tables for how it works.

@Dr-Irv
Copy link
Author

Dr-Irv commented Apr 6, 2020

Look at the example. The separator lines are identical. The second table is correct, but the first table is rendered too wide.

In the docs, it is written:

If a pipe table contains a row whose printable content is wider than the column width (see --columns), then the table will take up the full text width and the cell contents will wrap, with the relative cell widths determined by the number of dashes in the line separating the table header from the table body.

In this case, the printable content of the two tables are identical except for the characters (\mathcal B versus B, for example). The widths are identical.

So I think the way that pandoc is computing the line length is based on the LaTeX length.

If I look at the resulting LaTeX source, the first table has each cell in a minipage, the second table does not.

@jgm
Copy link
Owner

jgm commented Apr 7, 2020

Read the manual more carefully:

If a pipe table contains a row whose printable content is wider than the column width...

This is saying that the "relative widths based on the separator lines" feature only kicks in when you've got at least one content line that exceeds "columnwidth". That happens in your first table but not your second. If you want narrower columns in the first table, just use narrower separators (e.g. --).

@Dr-Irv
Copy link
Author

Dr-Irv commented Apr 7, 2020

But the content lines do not exceed the "columnwidth". Even with separators that are -, I get the same result.

Look at the picture and you'll see. The only difference between the math in each cell is that the first table uses \mathcal while the second column doesn't use \mathcal . I think that pandoc is computing the length of the content lines based on the number of characters used to express the math, as opposed to the length of the rendered math.

@jgm
Copy link
Owner

jgm commented Apr 7, 2020

I think that pandoc is computing the length of the content lines based on the number of characters used to express the math, as opposed to the length of the rendered math.

Yes: what's meant by "column width" is column width in the markdown source. (There's no way for pandoc to compute the column width in the rendered version; it would have to do TeX typesetting to know that. I know that this leads to odd results occasionally.)

But I was wrong to suggest that changes the separators to - would make a difference. Looks like currently pandoc assumes that when relative widths are needed, the table should take up full space, and the separators only affect proportions of widths of the columns.

A workaround for you would be to define a tex macro for the math so you can make the source shorter.

@jgm
Copy link
Owner

jgm commented Apr 7, 2020

Another workaround would be to specify a larger columnwidth on the command line.

@Dr-Irv
Copy link
Author

Dr-Irv commented Apr 7, 2020

I did try the macro thing, and that didn't help. If I use --columns=300, that seems to fix the problem.

I'd suggest writing something in the docs about how characters are counted (i.e., the characters in math mode count towards line width), or maybe when you count the width, you count each LaTeX token as a single character (but maybe that won't work since you don't parse the math)

@jgm
Copy link
Owner

jgm commented Apr 7, 2020

The macro trick should work if you specify -f markdown-latex_macros. This will prevent pandoc from resolving the macros when generating LaTeX, instead passing the macros directly to LaTeX, which is generally what you want. As manual says:

When latex_macros is disabled, the raw LaTeX and math will
not have macros applied. This is usually a better approach when
you are targeting LaTeX or PDF.

@Dr-Irv
Copy link
Author

Dr-Irv commented Apr 9, 2020

The macro trick should work if you specify -f markdown-latex_macros. This will prevent pandoc from resolving the macros when generating LaTeX, instead passing the macros directly to LaTeX, which is generally what you want. As manual says:

I still had to get the line shorter than 72 chars for it to work right (or just use --columns).

One note that might help. In the docs about pipe_tables it says:

If a pipe table contains a row whose printable content is wider than the column width

What is confusing here is the phrase "printable content". Maybe it should say "number of characters" or something like that

@jgm
Copy link
Owner

jgm commented Apr 9, 2020

I still had to get the line shorter than 72 chars for it to work right (or just use --columns).

Yes, that's what I meant: the idea was to use a macro to help do this.

jgm added a commit that referenced this issue Apr 9, 2020
@jgm jgm closed this as completed Apr 9, 2020
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

3 participants