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

[Latex] \today does not do anything #7905

Closed
MuntashirAkon opened this issue Feb 10, 2022 · 8 comments
Closed

[Latex] \today does not do anything #7905

MuntashirAkon opened this issue Feb 10, 2022 · 8 comments
Labels

Comments

@MuntashirAkon
Copy link

Explain the problem.
Latex has a special \today command to print today's date, and it is not outputting anything in the HTML format. This command can be very useful for serving documentations via a CI, for example.

Current workaround is to create a placeholder for a date and replace it with the date generated by other means (e.g. UNIX date).

Pandoc version?

pandoc 2.17.1.1
Compiled with pandoc-types 1.22.1, texmath 0.12.4, skylighting 0.12.2,
citeproc 0.6.0.1, ipynb 0.2
@jgm
Copy link
Owner

jgm commented Feb 10, 2022

This is by design. Pandoc allows you to include raw LaTeX in markdown, but it gets passed through only to LaTeX, not to HTML, which wouldn't know what to do with it.
You could use a Lua filter to find this bit of raw HTML in the AST and replace it with the date.

@jgm jgm closed this as completed Feb 10, 2022
@jgm
Copy link
Owner

jgm commented Feb 10, 2022

Sorry, I assumed your source was markdown, not LaTeX; you didn't say.
If the source is LaTeX, then we could consider parsing \today as a date.

@jgm jgm reopened this Feb 10, 2022
@jgm
Copy link
Owner

jgm commented Feb 10, 2022

 % pandoc -f latex -t native -s
\date{\today}
Pandoc
  Meta { unMeta = fromList [ ( "date" , MetaInlines [] ) ] }
  []

% pandoc -f latex+raw_tex -t native -s
\date{\today}
Pandoc
  Meta
    { unMeta =
        fromList
          [ ( "date"
            , MetaInlines [ RawInline (Format "latex") "\\today" ]
            )
          ]
    }
  []

@jgm
Copy link
Owner

jgm commented Feb 10, 2022

We could think about changing the first output above to

Pandoc
  Meta { unMeta = fromList [ ( "date" , MetaInlines [Str "2014-04-04"] ) ] }
  []

Of course there's the question what date format to use. We don't have awareness of localized date formats, so it's probably best just to use something like YYYY-mm-dd, even though this is a bit different from what you'd get in LaTeX.
We have a function in PandocMonad to getZonedTime, so this is feasible.
We could keep the second behavior above in the case where the raw_tex extension is enabled.

@MuntashirAkon
Copy link
Author

I think Latex uses dots rather than hyphens. But it's still better than producing nothing at all.

@jgm
Copy link
Owner

jgm commented Feb 10, 2022

The format LaTeX uses depends on your locale. When I use \today I get "February 10, 2022". Duplicating this locale-dependent behavior is probably too much trouble, though.

@tarleb
Copy link
Collaborator

tarleb commented Feb 10, 2022

Aside: there's an example in the Lua filters docs that adds a (localized) date: https://pandoc.org/lua-filters.html#setting-the-date-in-the-metadata

@jgm
Copy link
Owner

jgm commented Feb 10, 2022

We can easily generate a formatted date if we know what format to use. The missing piece is figuring out what format to use, e.g., based on the LOCALE environment variable or the lang metadata field. That's the complexity I'd rather not add.

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

No branches or pull requests

3 participants