quarto-ext / latex-environment Goto Github PK
View Code? Open in Web Editor NEWQuarto extension to output custom LaTeX environments.
Home Page: https://quarto-ext.github.io/latex-environment/
License: MIT License
Quarto extension to output custom LaTeX environments.
Home Page: https://quarto-ext.github.io/latex-environment/
License: MIT License
It seems that you have enabled arguments of environments, but not for commands? I'm trying to find a way to create this type of latex output:
\colorbox{red}{This text is in a red box}
However, the following file creates this output (note the square brackets).
\colorbox[red]{This text is in a red box}
\colorbox[red]{This text is in a red box} <!-- arguments are ignored -->
---
title: test
format:
pdf:
keep-tex: true
include-in-header:
text: |
\usepackage{xcolor}
filters:
- latex-environment
commands:
- colorbox
---
[This text is in a red box]{.colorbox options="red"}
[This text is in a red box]{.colorbox options="red" arguments="argument"}
The extension's name would not be great, but the syntax would be similar.
Or question is rather: What would be the output for format: typst
when this extension is used ?
See mentions in
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
Originally posted by @kwangkim in #1 (comment)
Hello,
I would like to know if you could make an extension that is kind of the inverse of the current one. That is, it will convert LaTeX syntax into quarto
syntax.
I have a lot of mathematical notes written in LaTeX that I would like to convert to blog posts, and doing a manual conversion would require too much work. It would be great if I could just copy the LaTeX source code to *.qmd
files. For example, the extension should make quarto
understand the following as a theorem:
\begin{theorem}[My Theorem]\label{th:some_theorem}
This is some theorem.
\end{theorem}
I hope that my request makes sense.
Thank you in advance for your reply!
It seems:
:::{#mylabel .myenv}
blah
:::
won't translate to:
\begin{myenv}\label{mylabel}
blah
\end{myenv}
As stated in #13, I want to use the latex-environment
filter to highlight specific parts of my code, using the listings
latex package / environment together with colorbox
. Per default, all latex code within a listings environment is ignored. However, I can specify an escape character in the package options (see here)
escapechar=⟨character⟩
orescapechar={}
If not empty the given character escapes the user to LATEX: all code between
two such characters is interpreted as LATEX code
So if I set the escapechar = |
, everything in between |
in my listing environment will be interpreted as latex code. Is there a way to get this input:
:::{.lstlisting}
[one]{.colorbox optons = "gray"}, [two]{.colorbox options = "red"}
:::
to this latex output (note the wrapping |
)?:
\begin{lstlisting}
|\colorbox{gray}{one}|, |\colorbox{red}{two}|
\end{lstlisting}
Dear developpers,
I am unsure if I hit a bug or if this works the way it should and I am using it in the wrong way.
I would like to have a .column
div in a .qmd
file be converted to a minipage
environment in latex and I thought this should work using this extension by using:
environments:
- column: minipage
However this does not produce any envs in latex.
Weirdly,
environments:
- minipage: column
produces a column
in latex
I found a work-around by adding 2 classes to my div :::{.column .minipage arguments="0.3\textwidth"}
Hi!
This quarto extension has stop working for me for some reason. When I try to run the example code I get this error
Error running filter _extensions/quarto-ext/latex-environment/latex-environment.lua: ...sions/quarto-ext/latex-environment/latex-environment.lua:66: attempt to call a nil value (field 'is_format') stack traceback:
I don't know how to code in Lua, but tracing the history of the commits I found that recently the following line has changed
if quarto.doc.isFormat("latex") then
# to
if quarto.doc.is_format("latex") then
if I remove this change (to the old isFormat
) everything works as usual.
I have the latest version of quarto installed, running on vscode with the quarto extension v1.46.0.
Can this filter be used for the following environment?
\begin{onlyenv}<⟨overlay specification⟩>
⟨environment contents⟩
\end{onlyenv}
please let me know
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.
I have installed the extension, but I get the error saying
Error running filter /opt/quarto/share/filters/main.lua:
Error running filter /home/../Documents/latex-environment:
Could not find executable /home/../Documents/latex-environment
stack traceback:
/opt/quarto/share/filters/main.lua:4026: in function </opt/quarto/share/filters/main.lua:4005>
[C]: in ?
[C]: in method 'walk'
/opt/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
/opt/quarto/share/filters/main.lua:449: in local 'callback'
/opt/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
/opt/quarto/share/filters/main.lua:495: in function </opt/quarto/share/filters/main.lua:476>
stack traceback:
/opt/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
/opt/quarto/share/filters/main.lua:449: in local 'callback'
/opt/quarto/share/filters/main.lua:454: in upvalue 'run_emulated_filter_chain'
/opt/quarto/share/filters/main.lua:495: in function </opt/quarto/share/filters/main.lua:476>
I have installed the extension and it says successfully installed. Please help what can be done here. Even the example code does not work.
This is a superb extension which I use often. Thank you for your great work.
I'm trying to use the extension to highlight specific parts in code blocks. My starting point is just to create a code block using the latex listings
package.
---
title: test
format:
pdf:
keep-tex: true
include-in-header:
text: |
\usepackage{listings}
filters:
- latex-environment
environments: [lstlisting]
---
:::{.lstlisting}
Paired t-test
data: blume$a and blume$b
:::
The desired latex output:
\begin{lstlisting}
Paired t-test
data: blume$a and blume$b
\end{lstlisting}
The created output:
\begin{lstlisting}
\begin{verbatim}
Paired t-test
\end{verbatim}
data: blume\(a and blume\)b
\end{lstlisting}
I'm guessing quarto ran its own filter over the code, turning the indented Paired t-test
to verbatim
and turning blume$a
to blume\(a
. Is there a way to prevent quarto from doing this?
First, thanks for developing latex-environment
!
I'm getting an error when the div is empty in the Quarto document, like this:
::: {.sumario}
:::
and in the LaTeX template:
\newenvironment{sumario}{
\thispagestyle{empty}
\singlespacing
\listoffigures
\newpage
\listoftables
\newpage
\tableofcontents
}{\pagebreak}
The error is:
Error running filter quarto-ext/latex-environment/latex-environment.lua:
latex-environment/latex-environment.lua:87: attempt to index a nil value (field 'integer index')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.