quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.93k stars 325 forks source link

Latex conflict when including the `titlesec` package #2686

Closed pedropark99 closed 2 years ago

pedropark99 commented 2 years ago

Bug description

Hello! I am using Quarto (version 0.9.531) on Windows 10 (I am running RStudio IDE version 2022.07.2+576), to output a PDF Curriculum Vitae. Everything was going great, until I decided to change the font and style of the section headers. And the logic way to do this in Latex, is by using the titlesec package. However, a Latex conflict is happening when I include the titlesec package. The resulting error produced by xelatex, when I include the titlesec package is this:

compilation failed- error
Argument of \paragraph has an extra }.
<inserted text> 
                \par 
l.1641 \ttl@extract\paragraph

see E:\Users\pedro\Documents\curriculo\titlesec-error.log for more information.

I started to research a little about this error, and, by doing some tests, I discovered that the source of the Latex error/conflict happens because of this section of the Latex code that is produced by default by Pandoc/Quarto:

% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
  \let\oldparagraph\paragraph
  \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
  \let\oldsubparagraph\subparagraph
  \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

In other words, if I remove this Latex code from titlesec-error.tex, and, try to compile the .tex file again with xelatex, everything works perfectly, without errors.

If I undestood correctly, looks to me that the Latex conflict is happening because titlesec looks for a specific definition of \paragraph command. However, with the latex code above, we are redefining the \paragraph command to a different version (I might be wrong).

Reproducible example

If you want to reproduce this error, you can do it by using the titlesec-error.qmd and pdf_config.tex files, which are exposed below. The titlesec-error.qmd file is composed of these lines:

---
title: "Pedro Duarte Faria"
format: 
  pdf:
    keep-tex: true
    documentclass: article
    number-sections: true
    colorlinks: true
    geometry:
      - top=2cm
      - bottom=3cm
      - left=2.5cm
      - right=2.5cm
    include-in-header:
      - pdf_config.tex

fontsize: 11pt
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

And the pdf_config.tex is composed of the following lines:

\usepackage{titlesec}
\titleformat*{\section}{\Large\bfseries\fontforsection}

More infos about the system and session

My tmlgr version is:

system("tlmgr --version")
tlmgr revision 63068 (2022-04-18 07:58:07 +0200)
tlmgr using installation: C:/Users/pedro/AppData/Roaming/TinyTeX
TeX Live (https://tug.org/texlive) version 2022

The basic info about my session:

sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.utf8  LC_CTYPE=Portuguese_Brazil.utf8    LC_MONETARY=Portuguese_Brazil.utf8
[4] LC_NUMERIC=C                       LC_TIME=Portuguese_Brazil.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.0 tools_4.2.0    tinytex_0.38   xfun_0.30 

Checklist

dragonstyle commented 2 years ago

Thanks for the detailed report! Try using block-headings: false to disable the Pandoc redefinition of those commands.

pedropark99 commented 2 years ago

Thank you @dragonstyle!!! I included block-headings: false in the YAML header, and the .qmd file compiled smoothly!

mikheyev commented 1 year ago

Hi @dragonstyle,

I am having the exact same problem on Mac OS, compiling via vscode. I am using the same example as @pedropark99

tlmgr --version
tlmgr revision 63068 (2022-04-18 07:58:07 +0200)
tlmgr using installation: /usr/local/texlive/2022
TeX Live (https://tug.org/texlive) version 2022

When I run render PDF with the block-headings: false option I get the following output:

running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999994 (TeX Live 2022) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

updating tlmgr

updating existing packages

compilation failed- error
Undefined control sequence.
<argument> \Large \bfseries \fontforsection 

l.146 \section{Quarto}\label{quarto}}                                 

This is a different error than without the block-headings switch:

compilation failed- error
Argument of \paragraph has an extra }.
<inserted text> 
                \par 
l.1641 \ttl@extract\paragraph
dragonstyle commented 1 year ago

I'm sorry that you've run into this. I'm guess this is some other issue - can you share a qmd document that causes the error for me to use trying to track the issue down?

mikheyev commented 1 year ago

That's the weird part. They are literally the same files from the example above:

qmd:

---
title: "Pedro Duarte Faria"
format: 
  pdf:
    keep-tex: true
    documentclass: article
    number-sections: true
    colorlinks: true
    geometry:
      - top=2cm
      - bottom=3cm
      - left=2.5cm
      - right=2.5cm
    include-in-header:
      - pdf_config.sty
block-headings: false
fontsize: 11pt
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

pdf_config.sty:

\usepackage{titlesec}
\titleformat*{\section}{\Large\bfseries\fontforsection}
dragonstyle commented 1 year ago

It looks to me like \fontforsection isn't defined in this simple example. Try updating the pdf_config.sty to read:

\usepackage{titlesec}
\titleformat*{\section}{\Large\bfseries\sffamily\color{blue}}
mikheyev commented 1 year ago

@dragonstyle This works! This solution could also help #4126.