Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: figure caption counter #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andywiecko
Copy link
Contributor

@andywiecko andywiecko commented Feb 11, 2025

Previously, figure and table captions were always numbered as 1 when nested inside certain tags, such as <center>.
This commit ensures correct sequential numbering.

Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
latex-css ❌ Failed (Inspect) Feb 12, 2025 6:04am

@vihuna
Copy link
Contributor

vihuna commented Feb 11, 2025

Yes, that was my fault. I somehow forgot to instantiate the counter: basically because I deliberately copy/paste the counters from tables (also not instantiated), and because for me, the numeration works fine without the counter initialization (at least for simple examples). So:

  • Does table counters work for you? They probably need to be fixed too, then.
  • Could you write some example where the numeration fails? I'm curious because it was working for me.

Previously, figure and table captions were always numbered as 1 when nested inside certain tags, such as `<center>`.
This commit ensures correct sequential numbering.
@andywiecko
Copy link
Contributor Author

andywiecko commented Feb 12, 2025

Does table counters work for you? They probably need to be fixed too, then.

Yes, this includes the tables. I also add caption in counter-reset.

Could you write some example where the numeration fails? I'm curious because it was working for me.

Below, you can find a minimal working example. The enumeration breaks when nested inside certain tags, such as <center>.

<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" href="https://latex.now.sh/style.min.css" />
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body id="top">
  <header>
    <h1><span class="latex">Test</h1>
  </header>

<main>
    <article>
        <center>
            <figure><figcaption></figcaption></figure>
        </center>
        <center>
            <figure><figcaption></figcaption></figure>
        </center>
        <center>
            <figure><figcaption></figcaption></figure>
        </center>

        <figure><figcaption></figcaption></figure>
        <figure><figcaption></figcaption></figure>
        <figure><figcaption></figcaption></figure>
    </article>
</main>

<script async defer data-domain="latex.now.sh" src="https://plausible.io/js/plausible.js"></script>
</body>

</html>

This will render as follows

image

@vihuna
Copy link
Contributor

vihuna commented Feb 12, 2025

Thanks for this example.

So, I think this particular error, and the reason because my simple examples did not fail, is because counter "scope".
If the first element with the counter was in the root of the body, then clearly increases the counter inside any other child element of its own; but not the other way around.

I should remind you that <center> tag is deprecated, in favor of CSS alignment. Maybe this means that LaTeX.css should provide some utility class for the alignment of text, figures, tables ...

@andywiecko
Copy link
Contributor Author

I should remind you that <center> tag is deprecated, in favor of CSS alignment. Maybe this means that LaTeX.css should provide some utility class for the alignment of text, figures, tables ...

Yes, I know it is deprecated; however, I believe many users of latex.css will use it anyway (including me 😃).
I think a custom class for centering would be awesome! $\LaTeX$ has the \centering command for such situations. How about adding a <centering> tag to the package?

@vihuna
Copy link
Contributor

vihuna commented Feb 13, 2025

Hi again @andywiecko. I don't know very well what you mean by:

How about adding a tag to the package?

But to encourage a deprecated tag will be a really bad markup practice.

At this moment, I think the easiest way to center figures would be something like

<figure>
  <img style="margin-left: auto; margin-right: auto;" src="..." /> 
  <figcaption style="text-align: center;"> [...] </figcaption>
</figure>

Moreover, I'm pretty sure that, if finally @vincentdoerig decides that some mechanism should be implemented to center/align figures/tables/text, it will be done through CSS classes.

A good point to discuss then, will be the CSS method used for the alignment: "margin-auto" or "flexbox" (taking into account the possibility of horizontally aligning various images in the same figure, for example).

And the problems because of LaTeX/HTML differences must not be forgotten. One thing that I don't like with current captions is that they are displayed with a different layout: figure captions are displayed using all the document main text area available, while table captions are limited to table width. That doesn't happen with LaTeX figure and table environments captions, where they both use all the main text area available.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants