styling of quotation marks in bookdown PDF output

Hi, I’m publishing a book with R bookdown in Estonian and would need to have the quotation marks styled as „...“.
I have set lang: et in YAML header of the index.Rmd and tried different options of adding \usepackage{csquotes} to the preamble.tex, e.g.:

The attempt to define the marks manually
\usepackage{csquotes}
\MakeOuterQuote{"}
% Manually redefine primary quotes to Estonian style: „...“
\DeclareRobustCommand{\openquote}{\quotedblbase}
\DeclareRobustCommand{\closequote}{\textquotedblright}

I’ve tried various options suggested by chatgpt but the attempts have no effect, seems that the straight quotations are converted to this “...” before my rules are applied.

Seems that I got it sorted, I'm pasting the solution here, as maybe someone else is also struggling with this. What helped was to add a lua filter to convert the quotes:

-- csquotes.lua
-- convert Pandoc quotes to LaTeX \enquote
if FORMAT:match('latex') then
function Quoted(el)
local open = (el.quotetype == 'SingleQuote') and [[\enquote*{]] or [[\enquote{]]
local out = { pandoc.RawInline('latex', open) }
for _, c in ipairs(el.content) do out[#out+1] = c end
out[#out+1] = pandoc.RawInline('latex', [[}]])
return out
end
end

Add a ref to lua filter in YAML header:

output:
bookdown::pdf_book:
latex_engine: xelatex
includes:
in_header: preamble.tex
pandoc_args: ["--lua-filter=csquotes.lua"]

And add quote formatting to pandoc.tex:

% language package
\usepackage{polyglossia}
\setmainlanguage{estonian}

% Quotation marks using csquotes
\usepackage[autostyle=false]{csquotes}
\DeclareQuoteStyle{estonian}
{\quotedblbase}% opening double -> „
{\textquotedblright}% ending double -> ”
{\quotesinglbase}% opening single -> ‚
{\textquoteright}% closing single -> ’
\setquotestyle{estonian}

\AtBeginDocument{%%
\renewcommand{\textquotedblleft}{„}%%
\renewcommand{\textquotedblright}{“}%%
\renewcommand{\textquoteleft}{‚}%%
\renewcommand{\textquoteright}{‘}%%
}

% Unicode
\usepackage{newunicodechar}
\newunicodechar{“}{„}
\newunicodechar{”}{“}
\newunicodechar{‘}{‚}
\newunicodechar{’}{‘}

Thanks for the solution.

Could you mark this as solved? It may help others with similar problems.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.