### Install apaquarto Extension via Terminal Source: https://github.com/wjschne/apaquarto/blob/main/README.md Installs the apaquarto Quarto extension directly from the terminal. This method is universal and does not require R. It prompts for trust confirmation and then for a folder name for installation. ```bash # Navigate to the desired folder # cd path/to/my/folder # Use the apaquarto template quarto use template wjschne/apaquarto ``` -------------------------------- ### Markdown Bullet List Example Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Illustrates how to create a bulleted list using Markdown syntax. ```markdown * Item A * Item B ``` -------------------------------- ### Install apaquarto Template and Extension via Terminal Source: https://github.com/wjschne/apaquarto/blob/main/docs/installation.html Commands to initialize a new project from the apaquarto template or add the extension to an existing project using the Quarto CLI. ```bash quarto use template wjschne/apaquarto ``` ```bash quarto add wjschne/apaquarto ``` -------------------------------- ### Install apaquarto Extension via R Console Source: https://github.com/wjschne/apaquarto/blob/main/README.md Installs the apaquarto Quarto extension using the 'quarto' R package. This method is suitable for R users and requires Quarto version 1.4 or higher. It prompts for trust confirmation before installation. ```r # Install the quarto package if not already installed install.packages("quarto") # Set working directory to the desired folder # setwd("path/to/my/folder") # Use the apaquarto template quarto::quarto_use_template("wjschne/apaquarto") ``` -------------------------------- ### Install apaquarto Extension via R Console Source: https://context7.com/wjschne/apaquarto/llms.txt R code to install the 'quarto' package and manage the apaquarto extension. This includes creating new projects from a template, adding the extension to existing documents, and automating the installation process. ```r # Install the quarto R package if not already installed install.packages("quarto") # Create a new apaquarto project with template quarto::quarto_use_template("wjschne/apaquarto") # Add apaquarto to an existing document (run from project directory) quarto::quarto_add_extension("wjschne/apaquarto") # Skip prompts for automated installation quarto::quarto_use_template("wjschne/apaquarto", no_prompt = TRUE) ``` -------------------------------- ### Install apaquarto via R Console Source: https://github.com/wjschne/apaquarto/blob/main/docs/installation.html Functions to install the apaquarto template or extension directly from the R console using the quarto R package. ```r quarto::quarto_use_template("wjschne/apaquarto", no_prompt = TRUE) ``` ```r quarto::quarto_add_extension("wjschne/apaquarto", no_prompt = TRUE) ``` -------------------------------- ### Install apaquarto Extension via Terminal Source: https://context7.com/wjschne/apaquarto/llms.txt Commands to install, add, update, or remove the apaquarto Quarto extension using the terminal. This allows for easy management of the extension for new or existing Quarto projects. ```bash # Create a new apaquarto project with template quarto use template wjschne/apaquarto # Add apaquarto to an existing Quarto document quarto add wjschne/apaquarto # Update to the latest version quarto update wjschne/apaquarto # Remove the extension quarto remove wjschne/apaquarto ``` -------------------------------- ### Markdown Formatting Examples Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Demonstrates various Markdown syntax for text formatting, including italics, bold text, subscript, superscript, en dashes, and em dashes. ```markdown *An italicized phrase* A **bolded** word H~2~O 21^st^ 6--8 hours of sleep It wasn't good---it was the best! ``` -------------------------------- ### Install the quarto R package Source: https://github.com/wjschne/apaquarto/blob/main/docs/installation.html Installs the quarto package from CRAN. This package is required to interact with Quarto CLI from within R. ```R install.packages("quarto") ``` -------------------------------- ### YAML Bibliography Configuration in ApaQuarto Source: https://github.com/wjschne/apaquarto/blob/main/docs/options.html Provides examples of how to specify bibliography files in YAML metadata, supporting both single file and multiple file configurations. ```yaml bibliography: mybibliography.bib ``` ```yaml bibliography: - mybibliography.bib - myotherbibliography.bib ``` -------------------------------- ### Basic Document YAML Configuration for apaquarto Source: https://context7.com/wjschne/apaquarto/llms.txt Example YAML front matter for configuring a Quarto document with apaquarto. It specifies document metadata such as title, author details, abstract, keywords, and desired output formats (docx, html, pdf, typst). ```yaml --- title: "My Paper's Title: A Full Analysis of Everything" shorttitle: "My Paper's Title" author: - name: W. Joel Schneider corresponding: true orcid: 0000-0002-8393-5316 email: schneider@temple.edu affiliations: - name: Temple University department: College of Education and Human Development address: 1301 Cecil B. Moore Ave. city: Philadelphia region: PA postal-code: 19122-6091 abstract: "This is my abstract." keywords: [keyword1, keyword2] author-note: disclosures: conflict of interest: The author has no conflict of interest to declare. bibliography: mybibfile.bib format: apaquarto-docx: default apaquarto-html: default apaquarto-pdf: default apaquarto-typst: default --- ``` -------------------------------- ### Navigate Directories via Terminal Source: https://github.com/wjschne/apaquarto/blob/main/docs/installation.html The standard command to change the current working directory in a terminal environment before running installation commands. ```bash cd "C:/Users/myname/Documents/MyProject/" ``` -------------------------------- ### JavaScript DOM Event Listener Setup Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Sets up an event listener for the DOMContentLoaded event to ensure the script runs after the HTML document is fully loaded and parsed. It includes helper functions for identifying code annotations and handling copy-to-clipboard functionality. ```javascript window.document.addEventListener("DOMContentLoaded", function (event) { const isCodeAnnotation = (el) => { for (const clz of el.classList) { if (clz.startsWith('code-annotation-')) { return true; } } return false; } const onCopySuccess = function(e) { // button target const button = e.trigger; // don't keep focus button.blur(); // flash "checked" button.classList.add('code-copy-button-checked'); var currentTitle = button.getAttribute("title"); button.setAttribute("title", "Copied!"); let tooltip; if (window.bootstrap) { button.setAttribute("data-bs-toggle", "tooltip"); button.setAttribute("data-bs-placement", "left"); button.setAttribute("data-bs-title", "Copied!"); tooltip = new bootstrap.Tooltip(button, { trigger: "manual", customClass: "code-copy-button-tooltip", offset: [0, -8] }); tooltip.show(); } setTimeout(function() { if (tooltip) { tooltip.hide(); button.removeAttribute("data-bs-title"); button.removeAttribute("data-bs-toggle"); button.removeAttribute("data-bs-placement"); } button.setAttribute("title", currentTitle); button.classList.remove('code-copy-button-checked'); }, 1000); // clear code selection e.clearSelection(); } const getTextToCopy = function(trigger) { const outerScaffold = trigger.parentElement.cloneNode(true); const codeEl = outerScaffold.querySelector('code'); for (const childEl of codeEl.children) { if (isCodeAnnotation(childEl)) { childEl.remove(); } } return codeEl.innerText; } const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', { text: getTextToCopy }); clipboard.on('success', onCopySuccess); if (window.document.getElementById('quarto-embedded-source-code-modal')) { const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', { text: getTextToCopy, container: window.document.getElementById('quarto-embedded-source-code-modal') }); clipboardModal.on('success', onCopySuccess); } var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//); var mailtoRegex = new RegExp(/^mailto:/); var filterRegex = new RegExp('/' + window.location.host + '/'); var isInternal = (href) => { return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href); } // Inspect non-navigation links and adorn them if external var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)'); for (var i=0; i { // Strip column container classes const stripColumnClz = (el) => { el.classList.remove("page-full", "page-columns"); if (el.children) { for (const child of el.children) { stripColumnClz(child); } } } stripColumnClz(note) if (id === null || id.startsWith('sec-')) { // Special case sections, only their first couple elements const container = document.createElement("div"); if (note.children && note.children.length > 2) { container.appendChild(note.children[0].cloneNode(true)); for (let i = 1; i < note.children.length; i++) { const child = note.children[i]; if (child.tagName === "P" && child.innerText === "") { continue; } else { container.appendChild(child.cloneNode(true)); break; } } if (w ``` -------------------------------- ### Add apaquarto to Existing Document via Terminal Source: https://github.com/wjschne/apaquarto/blob/main/README.md Adds the apaquarto extension to an existing .qmd file or project using the terminal. This command integrates the extension's features into your current document setup. ```bash # Navigate to the folder containing the .qmd file # cd path/to/my/folder # Add the apaquarto extension quarto add wjschne/apaquarto ``` -------------------------------- ### Initialize apaquarto template without prompts Source: https://github.com/wjschne/apaquarto/blob/main/docs/installation.html Uses the quarto_use_template function to initialize a new project based on the wjschne/apaquarto repository. The no_prompt parameter is set to TRUE to bypass interactive confirmation steps. ```R quarto::quarto_use_template("wjschne/apaquarto", no_prompt = TRUE) ``` -------------------------------- ### Initialize Tooltips for Document References Source: https://github.com/wjschne/apaquarto/blob/main/docs/installation.html This snippet iterates through all document references and initializes tippy tooltips. It handles both local and external link targets by fetching content if necessary. ```javascript const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]'); for (var i=0; i { const { slideConfig, trigger } = data; const href = trigger.getAttribute('href'); if (href !== null) { const imgEl = window.document.querySelector(`a[href="${href}"] img`); if (imgEl !== null && imgEl.getAttribute("src")?.startsWith("data:")) { slideConfig.href = imgEl.getAttribute("src"); } } }); lightboxQuarto.on('slide_after_load', (data) => { if (window.Quarto?.typesetMath) { window.Quarto.typesetMath(data.slideNode); } }); })(); ``` -------------------------------- ### APA Citation Syntax Source: https://context7.com/wjschne/apaquarto/llms.txt Provides examples of parenthetical, narrative, possessive, and suppressed-author citations using standard Markdown syntax. ```markdown ## Parenthetical Citations A sentence needing a citation [@smith2023]. Multiple citations [@smith2023; @jones2022]. With page numbers [@smith2023, pp. 35--41]. With prefix [e.g., @smith2023; @jones2022]. ## Narrative Citations @smith2023 found significant effects. @smith2023 [101-103] reported detailed results. ## Possessive Citations (apaquarto-specific) @smith2023 ['s] theory suggests... @smith2023 ['s, 35] original idea was influential. ## Keep Ampersand in Narrative (for tables) @smith2023 [&] reported the following results. @smith2023 [&, 's, 35--36] idea was influential. ## Suppress Author Name The year-only citation [-@smith2023] is useful after naming authors. Smith and Jones's [-@smith2023] theory states... ``` -------------------------------- ### Initialize Tippy.js Tooltips for Bibliographic References (JavaScript) Source: https://github.com/wjschne/apaquarto/blob/main/docs/resources.html Iterates through all 'a' elements with a 'role' of 'doc-biblioref'. For each, it finds associated citation information using 'findCites'. If found, it initializes a Tippy.js tooltip that displays a popup containing the full bibliographic entry content fetched from the DOM. ```javascript var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); for (var i = 0; i < bibliorefs.length; i++) { const ref = bibliorefs[i]; const citeInfo = findCites(ref); if (citeInfo) { tippyHover(citeInfo.el, function() { var popup = window.document.createElement('div'); citeInfo.cites.forEach(function(cite) { var citeDiv = window.document.createElement('div'); citeDiv.classList.add('hanging-indent'); citeDiv.classList.add('csl-entry'); var biblioDiv = window.document.getElementById('ref-' + cite); if (biblioDiv) { citeDiv.innerHTML = biblioDiv.innerHTML; } popup.appendChild(citeDiv); }); return popup.innerHTML; }); } } ``` -------------------------------- ### Omit Note Prefix in APA Note Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Shows how to suppress the default 'Note.' prefix in an APA note by starting the 'apa-note' string with 'NoNote'. This is useful for probability notes or custom formatting. ```r #| label: fig-myplot4 #| fig-cap: This Is the Figure Caption. #| apa-note: NoNote \* *p* < .05; \*\* *p* < .01 library(tidyverse) tibble(x = seq(0, 1, .001), y = dbeta(x,8,2)) %>% ggplot(aes(x,y)) + geom_area(fill = "royalblue", alpha = .5) ``` -------------------------------- ### Initialize Code Annotations and Citation Popups Source: https://github.com/wjschne/apaquarto/blob/main/docs/changelog.html This script attaches event listeners to code annotation elements to handle selection states and iterates through bibliographic references to inject dynamic content into hover popups. It relies on the DOM API and assumes the presence of a tippyHover function for rendering tooltips. ```javascript const annoteDls = window.document.querySelectorAll('dt[data-target-cell]'); for (const annoteDlNode of annoteDls) { annoteDlNode.addEventListener('click', (event) => { const clickedEl = event.target; if (clickedEl !== selectedAnnoteEl) { unselectCodeLines(); const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active'); if (activeEl) { activeEl.classList.remove('code-annotation-active'); } selectCodeLines(clickedEl); clickedEl.classList.add('code-annotation-active'); } else { unselectCodeLines(); clickedEl.classList.remove('code-annotation-active'); } }); } const findCites = (el) => { const parentEl = el.parentElement; if (parentEl) { const cites = parentEl.dataset.cites; if (cites) { return { el, cites: cites.split(' ') }; } else { return findCites(el.parentElement); } } else { return undefined; } }; var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); for (var i=0; i { for (const clz of el.classList) { if (clz.startsWith('code-annotation-')) { return true; } } return false; } const onCopySuccess = function(e) { const button = e.trigger; button.blur(); button.classList.add('code-copy-button-checked'); var currentTitle = button.getAttribute("title"); button.setAttribute("title", "Copied!"); let tooltip; if (window.bootstrap) { button.setAttribute("data-bs-toggle", "tooltip"); button.setAttribute("data-bs-placement", "left"); button.setAttribute("data-bs-title", "Copied!"); tooltip = new bootstrap.Tooltip(button, { trigger: "manual", customClass: "code-copy-button-tooltip", offset: [0, -8]}); tooltip.show(); } setTimeout(function() { if (tooltip) { tooltip.hide(); button.removeAttribute("data-bs-title"); button.removeAttribute("data-bs-toggle"); button.removeAttribute("data-bs-placement"); } button.setAttribute("title", currentTitle); button.classList.remove('code-copy-button-checked'); }, 1000); e.clearSelection(); } const getTextToCopy = function(trigger) { const outerScaffold = trigger.parentElement.cloneNode(true); const codeEl = outerScaffold.querySelector('code'); for (const childEl of codeEl.children) { if (isCodeAnnotation(childEl)) { childEl.remove(); } } return codeEl.innerText; } const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', { text: getTextToCopy }); clipboard.on('success', onCopySuccess); }); ``` -------------------------------- ### Create APA-Style Table with Multi-Paragraph Notes Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html This snippet demonstrates how to define multi-paragraph notes using YAML in Quarto and how to process a dataset using R's flextable package to produce an APA-compliant table. It includes data cleaning, summarization, and custom styling. ```yaml #| label: tbl-penguins #| tbl-cap: Some Descriptives #| apa-note: #| - First paragraph. #| - Second paragraph. ``` ```r library(flextable) penguins %>% select(-year, -island, -sex) %>% rename_with( \(x) str_replace_all(x, c(len = "length", dep = "depth")) %>% snakecase::to_title_case()) %>% na.omit() %>% summarizor(by = "Species") %>% as_flextable() %>% theme_apa() %>% valign(valign = "top") %>% surround(i = ~ stat == "mean_sd", border.top = flextable::fp_border_default()) %>% set_header_labels(variable = "Variable", stat = "Descriptive") ``` -------------------------------- ### Implement Clipboard Copy and Link Handling in Quarto Source: https://github.com/wjschne/apaquarto/blob/main/docs/resources.html This JavaScript code initializes clipboard functionality for code blocks and manages external link behavior within a Quarto-generated documentation site. It handles DOM events to provide user feedback upon copying and ensures proper navigation for external links. ```javascript window.document.addEventListener("DOMContentLoaded", function (event) { const icon = "\ue9cb"; const anchorJS = new window.AnchorJS(); anchorJS.options = { placement: 'right', icon: icon }; anchorJS.add('.anchored'); const isCodeAnnotation = (el) => { for (const clz of el.classList) { if (clz.startsWith('code-annotation-')) { return true; } } return false; } const onCopySuccess = function(e) { const button = e.trigger; button.blur(); button.classList.add('code-copy-button-checked'); var currentTitle = button.getAttribute("title"); button.setAttribute("title", "Copied!"); let tooltip; if (window.bootstrap) { button.setAttribute("data-bs-toggle", "tooltip"); button.setAttribute("data-bs-placement", "left"); button.setAttribute("data-bs-title", "Copied!"); tooltip = new bootstrap.Tooltip(button, { trigger: "manual", customClass: "code-copy-button-tooltip", offset: [0, -8]}); tooltip.show(); } setTimeout(function() { if (tooltip) { tooltip.hide(); button.removeAttribute("data-bs-title"); button.removeAttribute("data-bs-toggle"); button.removeAttribute("data-bs-placement"); } button.setAttribute("title", currentTitle); button.classList.remove('code-copy-button-checked'); }, 1000); e.clearSelection(); } const getTextToCopy = function(trigger) { const outerScaffold = trigger.parentElement.cloneNode(true); const codeEl = outerScaffold.querySelector('code'); for (const childEl of codeEl.children) { if (isCodeAnnotation(childEl)) { childEl.remove(); } } return codeEl.innerText; } const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', { text: getTextToCopy }); clipboard.on('success', onCopySuccess); }); ``` -------------------------------- ### Process Cross-References with Tippy.js Source: https://github.com/wjschne/apaquarto/blob/main/docs/index.html This code handles cross-references (a.quarto-xref) by attaching Tippy.js tooltips. It defines a function `processXRef` to clean up and format the content of cross-references, especially for sections. For external references or those not found locally, it attempts to fetch the content dynamically. It also includes logic for highlighting code lines based on annotations. ```javascript const xrefs = window.document.querySelectorAll('a.quarto-xref'); const processXRef = (id, note) => { // Strip column container classes const stripColumnClz = (el) => { el.classList.remove("page-full", "page-columns"); if (el.children) { for (const child of el.children) { stripColumnClz(child); } } } stripColumnClz(note) if (id === null || id.startsWith('sec-')) { // Special case sections, only their first couple elements const container = document.createElement("div"); if (note.children && note.children.length > 2) { container.appendChild(note.children[0].cloneNode(true)); for (let i = 1; i < note.children.length; i++) { const child = note.children[i]; if (child.tagName === "P" && child.innerText === "") { continue; } else { container.appendChild(child.cloneNode(true)); break; } } if (window.Quarto?.typesetMath) { window.Quarto.typesetMath(container); } return container.innerHTML } else { if (window.Quarto?.typesetMath) { window.Quarto.typesetMath(note); } return note.innerHTML; } } else { // Remove any anchor links if they are present const anchorLink = note.querySelector('a.anchorjs-link'); if (anchorLink) { anchorLink.remove(); } if (window.Quarto?.typesetMath) { window.Quarto.typesetMath(note); } if (note.classList.contains("callout")) { return note.outerHTML; } else { return note.innerHTML; } } } for (var i=0; i res.text()) .then(html => { const parser = new DOMParser(); const htmlDoc = parser.parseFromString(html, "text/html"); const note = htmlDoc.getElementById(id); if (note !== null) { const html = processXRef(id, note); instance.setContent(html); } }).finally(() => { instance.enable(); instance.show(); }); } } else { // See if we can fetch a full url (with no hash to target) // This is a special case and we should probably do some content thinning / targeting fetch(url) .then(res => res.text()) .then(html => { const parser = new DOMParser(); const htmlDoc = parser.parseFromString(html, "text/html"); const note = htmlDoc.querySelector('main.content'); if (note !== null) { // This should only happen for chapter cross references // (since there is no id in the URL) // remove the first header if (note.children.length > 0 && note.children[0].tagName === "HEADER") { note.children[0].remove(); } const html = processXRef(null, note); instance.setContent(html); } }).finally(() => { instance.enable(); instance.show(); }); } }, function(instance) { }); } let selectedAnnoteEl; const selectorForAnnotation = ( cell, annotation) => { let cellAttr = 'data-code-cell="' + cell + '"'; let lineAttr = 'data-code-annotation="' + annotation + '"'; const selector = 'span[' + cellAttr + '][' + lineAttr + ']'; return selector; } const selectCodeLines = (annoteEl) => { const doc = window.document; const targetCell = annoteEl.getAttribute("data-target-cell"); const targetAnnotation = annoteEl.getAttribute("data-target-annotation"); const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation)); const lines = annoteSpan.getAttribute("data-code-lines").split(","); const lineIds = lines.map((line) => { return targetCell + "-" + line; }) let top = null; let height = null; let parent = null; if (lineIds.length > 0) { //compute the position of the single el (top and bottom and make a div) const el = window.document.getElementById(lineIds[0]); top = el.offsetTop; height = el.offsetHeight; parent = el.parentElement.parentElement; if (lineIds.length > 1) { const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]); const bottom = lastEl.offsetTop + lastEl.offsetHeight; height = bottom - top; } if (top !== null && height !== null && parent !== null) { // cook up a div (if necessary) and position it let div = window.document.getElementById("code-annotation-line-highlight"); if (div === null) { div = window.document.createElement("div"); div.setAttribute("id", "code-annotation-line-highlight"); div.style.position = 'absolute'; p ``` -------------------------------- ### Importing and Formatting Figures with Markdown Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Demonstrates how to embed images in Quarto documents using Markdown syntax. It includes options for captions, labels, alternative text, width, and APA-style notes. This method is useful for static images where direct Markdown control is preferred. ```markdown ![A Simple Mediation Model](sampleimage.png){ #fig-myimportedimage width="5in" fig-alt="A mediation model in which A causes B, and B causes C." apa-note="Variable A indirectly causes Variable C." } ``` -------------------------------- ### Initialize Tippy Tooltips for Elements Source: https://github.com/wjschne/apaquarto/blob/main/docs/apashiny.html Configures and attaches Tippy.js tooltips to DOM elements. It supports custom content functions and trigger/untrigger callbacks to manage interactive popovers. ```javascript function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) { const config = { allowHTML: true, maxWidth: 500, delay: 100, arrow: false, appendTo: function(el) { return el.parentElement; }, interactive: true, interactiveBorder: 10, theme: 'quarto', placement: 'bottom-start', }; if (contentFn) { config.content = contentFn; } if (onTriggerFn) { config.onTrigger = onTriggerFn; } if (onUntriggerFn) { config.onUntrigger = onUntriggerFn; } window.tippy(el, config); } ``` -------------------------------- ### Initialize Quarto Code Annotations Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Attaches click event listeners to document definition terms (DT) to toggle code annotation highlighting. It manages the selection state of active annotation elements. ```javascript const annoteDls = window.document.querySelectorAll('dt[data-target-cell]'); for (const annoteDlNode of annoteDls) { annoteDlNode.addEventListener('click', (event) => { const clickedEl = event.target; if (clickedEl !== selectedAnnoteEl) { unselectCodeLines(); const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active'); if (activeEl) { activeEl.classList.remove('code-annotation-active'); } selectCodeLines(clickedEl); clickedEl.classList.add('code-annotation-active'); } else { unselectCodeLines(); clickedEl.classList.remove('code-annotation-active'); } }); } ``` -------------------------------- ### Handle Tippy.js Hover for Cross-References Source: https://github.com/wjschne/apaquarto/blob/main/docs/options.html This code sets up `tippyHover` instances for elements identified as cross-references (xrefs). It defines a callback function that is executed when a tooltip is shown. This callback fetches and processes cross-reference content, enabling or disabling the tooltip instance as needed. It also handles fetching full URLs for chapter cross-references. ```javascript for (var i=0; i res.text()) .then(html => { const parser = new DOMParser(); const htmlDoc = parser.parseFromString(html, "text/html"); const note = htmlDoc.getElementById(id); if (note !== null) { const html = processXRef(id, note); instance.setContent(html); } }).finally(() => { instance.enable(); instance.show(); }); } } else { fetch(url) .then(res => res.text()) .then(html => { const parser = new DOMParser(); const htmlDoc = parser.parseFromString(html, "text/html"); const note = htmlDoc.querySelector('main.content'); if (note !== null) { if (note.children.length > 0 && note.children[0].tagName === "HEADER") { note.children[0].remove(); } const html = processXRef(null, note); instance.setContent(html); } }).finally(() => { instance.enable(); instance.show(); }); } }, function(instance) { }); } ``` -------------------------------- ### Creating Tables with R and Flextable in Quarto Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Shows how to generate tables within R code chunks in Quarto documents. It utilizes the flextable package for creating well-formatted tables, including APA styling, alignment, and notes. The chunk options `label`, `tbl-cap`, `ft.align`, and `apa-note` are used for customization. ```r #| label: tbl-mytable #| tbl-cap: My Table #| ft.align: left #| apa-note: A note below table library(tidyverse) library(flextable) tibble(Letters = c("A", "B", "C"), Numbers = 1:3) %>% flextable() %>% theme_apa() ``` -------------------------------- ### Create Markdown Table with apaquarto Note Source: https://github.com/wjschne/apaquarto/blob/main/docs/writing.html Demonstrates how to define a simple Markdown table with a custom caption and an apa-note attribute for APA-style formatting. ```markdown | Letters | Numbers | |:-------:|:-------:| | A | 1 | | B | 2 | | C | 3 | : My Caption {#tbl-mytable2 apa-note="Note below table" data-quarto-disable-processing="true"} ``` -------------------------------- ### Configure Authors and Affiliations with Reference IDs Source: https://github.com/wjschne/apaquarto/blob/main/docs/options.html Demonstrates how to decouple author affiliations by defining them in a central list and referencing them by ID. This approach simplifies metadata management when multiple authors share the same institutions. ```yaml author: - name: Fred Jones affiliation: - ref: temple - ref: tamu - name: Wanda James affiliation: - ref: temple - ref: ucb affiliations: - id: temple name: Temple University - id: tamu name: "Texas A&M University" - id: ucb name: University of California, Berkeley ``` -------------------------------- ### Configure Meta-Analysis Citations Source: https://context7.com/wjschne/apaquarto/llms.txt Demonstrates how to use the nocite field to include specific studies in the References section with meta-analysis asterisks. ```yaml --- title: "Meta-Analysis of Intervention Effects" abstract: "This meta-analysis examines..." bibliography: references.bib nocite: | @study1, @study2, @study3, @study4, @study5 meta-analysis: true format: apaquarto-docx: default --- ``` -------------------------------- ### Bibliographic Reference Tooltip Generation Source: https://github.com/wjschne/apaquarto/blob/main/docs/apashiny.html Traverses the DOM to find citation data and initializes tooltips using the tippy library for bibliographic references. ```javascript const findCites = (el) => { const parentEl = el.parentElement; if (parentEl) { const cites = parentEl.dataset.cites; if (cites) { return { el, cites: cites.split(' ') }; } else { return findCites(el.parentElement); } } return undefined; }; ``` -------------------------------- ### Implement Code Annotation Highlighting Source: https://github.com/wjschne/apaquarto/blob/main/docs/installation.html Provides functions to select and highlight specific lines of code within a document. It manages DOM elements for visual indicators and includes a throttle utility to optimize performance during window resize events. ```javascript const selectCodeLines = (annoteEl) => { const targetCell = annoteEl.getAttribute("data-target-cell"); const targetAnnotation = annoteEl.getAttribute("data-target-annotation"); const annoteSpan = window.document.querySelector(targetAnnotation); const top = annoteSpan.offsetTop; const height = annoteSpan.offsetHeight; let div = window.document.getElementById("code-annotation-line-highlight"); if (div === null) { div = window.document.createElement("div"); div.setAttribute("id", "code-annotation-line-highlight"); div.style.position = 'absolute'; parent.appendChild(div); } div.style.top = top - 2 + "px"; div.style.height = height + 4 + "px"; div.style.left = 0; }; const throttle = (fn, ms) => { let throttle = false; let timer; return (...args) => { if(!throttle) { fn.apply(this, args); throttle = true; } else { if(timer) clearTimeout(timer); timer = setTimeout(() => { fn.apply(this, args); timer = throttle = false; }, ms); } }; }; ``` -------------------------------- ### YAML Abstract Formatting in ApaQuarto Source: https://github.com/wjschne/apaquarto/blob/main/docs/options.html Shows how to format the abstract in YAML metadata, distinguishing between single-paragraph and multi-paragraph abstracts. ```yaml abstract: This is a single-paragraph abstract. ``` ```yaml abstract: | | This is the first paragraph. | This is the second paragraph. | This the third paragraph. ``` -------------------------------- ### YAML Keywords Formatting in ApaQuarto Source: https://github.com/wjschne/apaquarto/blob/main/docs/options.html Demonstrates two methods for specifying keywords in YAML metadata: a comma-separated list within brackets and a multiline indented list. ```yaml keywords: [First keyword, Second keyword, Third keyword] ``` ```yaml keywords: - First keyword - Second keyword - Third keyword ``` -------------------------------- ### Highlight Code Lines and Manage Annotations Source: https://github.com/wjschne/apaquarto/blob/main/docs/apashiny.html Calculates the position and dimensions of code lines to render an overlay div. It includes logic to create or update highlight elements and gutter markers, and a function to remove these elements when unselecting. ```javascript const selectCodeLines = (lineIds) => { if (lineIds.length > 0) { const el = window.document.getElementById(lineIds[0]); let top = el.offsetTop; let height = el.offsetHeight; let parent = el.parentElement.parentElement; if (lineIds.length > 1) { const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]); const bottom = lastEl.offsetTop + lastEl.offsetHeight; height = bottom - top; } if (top !== null && height !== null && parent !== null) { let div = window.document.getElementById("code-annotation-line-highlight"); if (div === null) { div = window.document.createElement("div"); div.setAttribute("id", "code-annotation-line-highlight"); div.style.position = 'absolute'; parent.appendChild(div); } div.style.top = top - 2 + "px"; div.style.height = height + 4 + "px"; } } }; const unselectCodeLines = () => { const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"]; elementsIds.forEach((elId) => { const div = window.document.getElementById(elId); if (div) { div.remove(); } }); }; ``` -------------------------------- ### Format Appendices and Cross-References Source: https://context7.com/wjschne/apaquarto/llms.txt Shows how to define appendices using headers and cross-reference them within the document text. ```markdown # Method We conducted a reliability analysis (see @apx-reliability for details). # Reliability Analysis of the Individual Differences Scale {#apx-reliability} The Individual Differences Scale demonstrated excellent internal consistency. ```{r} #| label: tbl-reliability #| tbl-cap: Internal Consistency Coefficients ``` ``` -------------------------------- ### Configure PDF Document Modes Source: https://context7.com/wjschne/apaquarto/llms.txt Sets document-specific options for PDF output, including document modes, paper size, and journal-specific metadata. ```yaml --- title: "Journal Article Submission" shorttitle: "Journal Article" author: - name: Author Name affiliations: University Name abstract: "Abstract text here." format: apaquarto-pdf: documentmode: jou fontsize: 12pt a4paper: false numbered-lines: true floatsintext: true draftall: false donotrepeattitle: false journal: "Psychological Review" volume: "2024, Vol. 131, No. 2, 10--60" copyrightnotice: "2024" copyrightext: "All rights reserved" course: "Introduction to Statistics (EDUC 5101)" professor: "Dr. Smith" duedate: "12/22/2024" --- ``` -------------------------------- ### Citation Reference Handling (JavaScript) Source: https://github.com/wjschne/apaquarto/blob/main/docs/options.html Processes citation references ('a[role="doc-biblioref"]') to display citation information using tippy.js tooltips. It finds associated citation data from parent elements and dynamically generates popups with bibliography entries. ```javascript const findCites = (el) => { const parentEl = el.parentElement; if (parentEl) { const cites = parentEl.dataset.cites; if (cites) { return { el, cites: cites.split(' ') }; } else { return findCites(el.parentElement) } } else { return undefined; } }; var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); for (var i=0; i