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 writer: support beamer overlays (take 2) #9215

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lawcho
Copy link
Contributor

@lawcho lawcho commented Nov 24, 2023

This PR is a successor to #9203, with a different implementation.

This PR allows ergonomic beamer scripting, via attributes on pandoc elements.

  • The key-value attributes [only,visible,uncover,invisible] are interpreted specially by the beamer writer
  • These can be applied to any (attribute-carrying) Block or Inline element
  • The generated beamer-LaTeX code for those elements is wrapped in \begin{XXXenv}<YYY>...\end{XXXenv},
    for each (special) attribute pair (XXX,YYY)

Example

I can write a presentation in markdown:

---
header-includes: |
  \setbeamercovered{transparent=25}
---


# How to print a tree {.t}

`{-# LANGUAGE StandaloneDeriving #-}`{.haskell visible=5-}

`data Tree a = Leaf a | Branch [Tree a]`{.haskell}

![](https://upload.wikimedia.org/wikipedia/commons/1/1c/Haskell-Logo.svg){only=1}

[*Many* options:]{invisible=1-5}

```{.haskell visible=3,6-}
  deriving (Show)
```

```{.haskell visible=4,6-}
instance (Show a) => Show (Tree a) where
  show :: Tree a -> String
  show (Leaf x) = "Leaf (" ++ show x ++ ")"
  show (Branch ts) = "Branch " ++ show ts
```

`deriving instance (Show a) => Show (Tree a)`{.haskell visible=5-}

## Discussion {visible=7-}

::::: {uncover=8-}
* Not all at once
  * `OverlappingInstances`
  * [Choose max. 1!]{only=9}
:::::
::::: {uncover=11-}
* See also
  * [Tweag on run-time instances](https://www.tweag.io/blog/2021-04-08-capabilities-ad-hoc-interpreters/){only=12-}
:::::

Then pandoc src.md -o slides.pdf --to beamer generates a 12-page slideshow:

Screenshot from 2023-11-24 18-18-54

slides.pdf

Pandoc elements with the `only=SPEC` attribute generate LaTeX code
wrapped in `\begin{onlyenv}<SPEC>...\end{onlyenv}

Unlike f0785a, this implementation is minimally invasive,
and is compatible with a wide range of generated LaTeX code,
including the `\Verb|` used by fenced code blocks.

The wrapping only occurs for beamer-LaTeX output,
never for plain LaTeX output
Now `visible`, `uncover`, and `visible` are supported,
in addition to `only`.

When multiple overlay-generating attributes are provided,
nested environments are generated (instead of a warning).
@jgm
Copy link
Owner

jgm commented Nov 26, 2023

I guess invisibleenv, etc., are built-in beamer environments, requiring no special definition?

@lawcho
Copy link
Contributor Author

lawcho commented Nov 27, 2023

Yes, invisibleenv, onlyenv, etc. are built-in beamer environments.

N.B. after writing this PR, I managed to get similar results with a lua filter:

-- Convert ELEM{only=X} to \begin{onlyenv}<X>ELEM\end{onlyenv}
-- (and likewise for several other overlay types)

local overlays_supported = pandoc.List
  {"only","uncover","visible","invisible","action","alert"}

local function tex_wrap(block_mode,pre,el,post)
  return block_mode
      and pandoc.Blocks
    {pandoc.RawBlock("tex",pre), el, pandoc.RawBlock("tex",post)}
      or pandoc.Inlines
    {pandoc.RawInline("tex",pre), el, pandoc.RawInline("tex",post)}
end

local function wrap_in_overlays(block_mode,el)
  for k,v in pairs(el.attributes) do
    el = overlays_supported:includes(k)
      and tex_wrap(block_mode,"\\begin{"..k.."env}<"..v..">",el,"\\end{"..k.."env}")
      or el
  end
  return el
end

local function wrap_block(el) return wrap_in_overlays(true,el) end
local function wrap_inline(el) return wrap_in_overlays(false,el) end

return {{
  -- These block elements have attributes
  CodeBlock = wrap_block,
  Div = wrap_block, 
  Figure = wrap_block,
  Table = wrap_block,
  -- These inline elements have attributes
  Code = wrap_inline,
  Image = wrap_inline,
  Link = wrap_inline,
  Span = wrap_inline,
}}

So I'm no longer sure that this PR is worth merging.

@lawcho
Copy link
Contributor Author

lawcho commented Jan 26, 2024

8 presentations later (half of these), a lua filter still covers my animation requirements.

So I'm closing this PR as not-wanted.

@lawcho lawcho closed this Jan 26, 2024
@jgm
Copy link
Owner

jgm commented Feb 5, 2024

If you wouldn't mind keeping this open, it's still something I'd consider...it could be a useful feature in pandoc.

@lawcho lawcho reopened this Feb 6, 2024
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.

None yet

2 participants