wjschne / apaquarto

A quarto extension for creating APA7 documents in .docx, .html, and .pdf formats
https://wjschne.github.io/apaquarto/
Creative Commons Zero v1.0 Universal
166 stars 14 forks source link

Using a different font in jou #40

Closed drfurtado closed 6 months ago

drfurtado commented 7 months ago

Could you please help me change my template so that it used the font type below? I am not entirely sure what I should change in the template to use this font. Any help is greatly appreciated. I read your help site but was not able to find the answer.

% Color and font \usepackage{xcolor} \definecolor{JournalBlue}{RGB}{0, 0, 0} % Set the JournalBlue color to black \usepackage{tgbonum}

wjschne commented 7 months ago

apaquarto uses XeLaTeX, so it can handle any system font. TeX Gyre Bonum can be installed from https://www.fontsquirrel.com/fonts/tex-gyre-bonum

Try the latest version of apaquarto and in your yaml meta data add this:

mainfont: TeX Gyre Bonum
header-insert: |
  \usepackage{xcolor}
  \definecolor{JournalBlue}{RGB}{0, 0, 0} 

I could not insert things in the header the usual Quarto way (include-in-header) because Quarto automatically inserts a lot of other stuff that breaks things for apaquarto.

mvuorre commented 6 months ago

Hi, I just started a clean project with quarto use template wjschne/apaquarto, and tried to render minimal.qmd with the above added to the YAML. Unfortunately it doesn't work:

$ quarto render minimal.qmd -t apaquarto-pdf                                                                        1 ↵
pandoc
  to: latex
  output-file: minimal.tex
  template: _extensions/wjschne/apaquarto/apatemplate.tex
  standalone: true
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf
  citeproc: false
  toc: false

metadata
  block-headings: false
  fig-cap-location: top
  tbl-cap-location: top
  cap-location: top
  csl: _extensions/wjschne/apaquarto/apa.csl
  documentclass: apa7
  link-ciations: false
  suppress-bibliography: false
  hyperrefoptions:
    - linktoc=none
  classoption: 'colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue'
  title: My Title
  shorttitle: Short Title in Running Header
  author:
    - name: Jane Doe
      corresponding: true
      orcid: 0000-0000-0000-0001
      email: janedoe@generic.edu
      affiliations:
        - name: Generic University
          department: Department of Scholarly Studies
          address: 1234 Capital St.
          city: New York
          region: NY
          country: USA
          postal-code: 12084-1234
  author-note:
    status-changes:
      affiliation-change: null
      deceased: null
    disclosures:
      study-registration: null
      data-sharing: null
      related-report: null
      conflict-of-interest: null
      financial-support: null
      gratitude: null
      authorship-agreements: null
  abstract: This document is a template.
  keywords:
    - keyword1
    - keyword2
    - keyword3
  bibliography:
    - bibliography.bib
  mainfont: TeX Gyre Bonum
  header-insert: |
    \usepackage{xcolor}
    \definecolor{JournalBlue}{RGB}{0, 0, 0}
  documentmode: man

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

updating tlmgr

updating existing packages
ERROR:
compilation failed- error
Undefined control sequence.
l.114 \defaultfontfeatures
                          {Scale=MatchLowercase}

see minimal.log for more information.

I figure this is because the above command needs the fontspec package. But this doesn't help:

header-insert: |
  \usepackage{xcolor}
  \usepackage{fontspec}
  \definecolor{JournalBlue}{RGB}{0, 0, 0} 

Because those lines are inserted below the \defaultfontfeatures{Scale=MatchLowercase} line in minimal.tex. If I go in manually and add \usepackage{fontspec} to line 114 of minimal.tex, I can then render the PDF successfully with the Tex Gyre Bonum font (wow this is not a good looking font imo 😅).

I tried different variations of entering \usepackage{fontspec} into the YAML but alas none worked. Is there a way to load this package by default at the top perhaps?

wjschne commented 6 months ago

@mvuorre, I believe the problem is fixed now. \usepackage{fontspec} is now loaded explicitly whenever mainfont is set in YAML

mvuorre commented 6 months ago

Great! Works like a charm 🚀

Now just adding mainfont: "Comic Sans MS" to the minimal template creates the following

image
bethanyhgardner commented 6 months ago

Huh, I seem to be missing something, because nothing I've tried will get the font to change. If I modify the default template to include mainfont, either under the apaquarto-pdf key like I'd expect:

format:
  apaquarto-docx: default
  apaquarto-html: default
  apaquarto-pdf:
    # Can be jou (journal), man (manuscript), stu (student), or doc (document)
    documentmode: man
    mainfont: "Comic Sans MS"

but also at the top level:

mainfont: "Comic Sans MS"
format:
  apaquarto-docx: default
  apaquarto-html: default
  apaquarto-pdf:
    # Can be jou (journal), man (manuscript), stu (student), or doc (document)
    documentmode: man

I get a similar error as above:

processing file: example.qmd                                                                                
output file: example.knit.md
pandoc 
  to: latex
  output-file: example.tex
  template: _extensions/wjschne/apaquarto/apatemplate.tex
  standalone: true
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf
  citeproc: false
  toc: false

metadata
  block-headings: false
  fig-cap-location: top
  tbl-cap-location: top
  cap-location: top
  csl: _extensions/wjschne/apaquarto/apa.csl
  documentclass: apa7
  link-ciations: false
  suppress-bibliography: false
  hyperrefoptions:
    - linktoc=none
  classoption: 'colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue'
  title: Using Quarto to Generate Documents in APA Style (7th Edition)
  shorttitle: Template for the apaquarto Extension
  ...
  lang: en
  documentmode: man
  mainfont: Comic Sans MS

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

updating tlmgr

updating existing packages
ERROR: 
compilation failed- error
Undefined control sequence.
l.241 \xpatchcmd
                {\appendix} 

see example.log for more information.

And here's my Quarto/R info:

Quarto 1.4.549
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.549
      Path: C:\Program Files\Quarto\bin
      CodePage: 1252
[>] Checking tools....................OK
      TinyTeX: v2024.04
      Chromium: (not installed)
[>] Checking LaTeX....................OK
      Using: TinyTex
      Path: C:\Users\betha\AppData\Roaming\TinyTeX\bin\windows\
      Version: 2024
[>] Checking basic markdown render....OK
[>] Checking Python 3 installation....OK
      Version: 3.8.18 (Conda)
      Path: C:/ProgramData/Anaconda3/python.exe
      Jupyter: 5.4.0
      Kernels: python3
[>] Checking Jupyter engine render....OK
[>] Checking R installation...........OK
      Version: 4.3.2
      Path: C:/PROGRA~1/R/R-43~1.2
      LibPaths:
        - C:/Users/betha/.R
        - C:/Program Files/R/R-4.3.2/library
      knitr: 1.46
      rmarkdown: 2.26
[>] Checking Knitr engine render......OK

But thanks for making this! It was useful to learn enough Latex to start trying to create something approximating APA format myself, but this is speeding things up a lot. I am simply a Times New Roman hater.

wjschne commented 6 months ago

@bethanyhgardner, I replicated your error. I think I have fixed it. Upgrade to version 3.5.2 (i.e., the latest version) and let me know if your error is gone.

bethanyhgardner commented 6 months ago

Thanks! Now rendering Times New Roman-free documents and taking a peek at the commit to see how it works.