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

Supports setting attributes on the environment #1

Closed
cderv opened this issue Jun 30, 2022 · 4 comments
Closed

Supports setting attributes on the environment #1

cderv opened this issue Jun 30, 2022 · 4 comments

Comments

@cderv
Copy link
Contributor

cderv commented Jun 30, 2022

Some LaTeX environment will need to have attributes set, not only a class equivalent.

See https://bookdown.org/yihui/rmarkdown-cookbook/custom-blocks.html for how it works in R Markdown.

We could port the idea and do

:::: {.center}

::: {.minipage latex="{.5\linewidth}"}
This paragraph will be centered on the page, and
its width is 50% of the width of its parent element.
:::

::::

aim is to write

\begin{center}
\begin{minipage}{.5\linewidth}
This paragraph will be centered on the page, and
its width is 50\% of the width of its parent element.
\end{minipage}
\end{center}

We could me more precise on the attribute name, but latex clearly means this is to be used only with LaTeX. We would for sure ignore for HTML this attribute.

We also did also made soemthing generic where you need to add the brackets as an environement could be (more on that in https://tex.stackexchange.com/a/302040/209358)

\begin{foo}[option]{argument}
body
\end{foo}

which would be written

::: {.foo latex="[option]{argument}"}
body
:::

Anyway, happy to port the feature here. Just wanted to discuss with you what you think is the best way to express that on the custom div.

@cderv
Copy link
Contributor Author

cderv commented Jun 30, 2022

One proposal:

::: {.foo options="option" arguments="argument"}
body
:::

to transform

\begin{foo}[option]{argument}
body
\end{foo}

@kwangkim
Copy link

A command may need options.

For example, in an exam class,

\begin{parts}
\part[2] Question 1
\part[3] Question 2
\end{parts}

One possible suggestion is

:::{.parts}
[]{.part options="2"} Question 1
[]{.part options="3"} Question 2
:::

With

local function writeCommands(spanEl)
  if quarto.doc.isFormat("latex") then
    for k,v in pairs(classCommands) do
      if spanEl.attr.classes:includes(k) then
        local result = spanEl.content
        local beginCommand = pandoc.RawInline('latex', '\\' .. pandoc.utils.stringify(v) .. '{')
        local endCommand = pandoc.RawInline('latex', '}')

        local opts = spanEl.attr.attributes['options']
        if opts then
          beginCommand = pandoc.RawInline('latex', '\\' .. pandoc.utils.stringify(v) .. '[' .. opts .. ']{')
        end

        table.insert(result, 1, beginCommand)
        table.insert(result, endCommand)

        return result
      end
    end
  end
end

@cderv
Copy link
Contributor Author

cderv commented Sep 19, 2022

Thanks @kwangkim I have moved this as a new feature request as I believe even if related this is better to track and discuss independently

@AngelBerihuete
Copy link

Hi @kwangkim ! I'm wondering if you had success on creating a document with exam package. I'm struggling with solution and question environments, but I have lots of errors.

Can you share an example using the exam package?

Thanks.

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

No branches or pull requests

4 participants