pages/posts/ci-gitlab-latex.html
2026-03-26 17:49:12 +00:00

906 lines
No EOL
48 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.6.39">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Louis Lacoste">
<meta name="dcterms.date" content="2025-09-23">
<title>Faire une CI LaTeX avec GitLab Louis Lacoste</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
<script src="../site_libs/clipboard/clipboard.min.js"></script>
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="../site_libs/quarto-search/fuse.min.js"></script>
<script src="../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../">
<script src="../site_libs/quarto-html/quarto.js"></script>
<script src="../site_libs/quarto-html/popper.min.js"></script>
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../site_libs/quarto-html/anchor.min.js"></script>
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../site_libs/quarto-html/quarto-syntax-highlighting-e26003cea8cd680ca0c55a263523d882.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../site_libs/bootstrap/bootstrap-86ddb94b6c65cfb424b1f9464cc27ff8.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 50,
"keyboard-shortcut": [
"f",
"/",
"s"
],
"show-item-context": false,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-text-placeholder": "",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
<link rel="stylesheet" href="../styles.css">
</head>
<body class="nav-fixed">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top quarto-banner">
<nav class="navbar navbar-expand-lg " data-bs-theme="dark">
<div class="navbar-container container-fluid">
<div class="navbar-brand-container mx-auto">
<a class="navbar-brand" href="../index.html">
<span class="navbar-title">Louis Lacoste</span>
</a>
</div>
<div id="quarto-search" class="" title="Search"></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav navbar-nav-scroll me-auto">
<li class="nav-item">
<a class="nav-link" href="../index.html">
<span class="menu-text">Home</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../posts.html">
<span class="menu-text">Posts</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../teaching.html">
<span class="menu-text">Teaching</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../publications.html">
<span class="menu-text">Publications</span></a>
</li>
</ul>
</div> <!-- /navcollapse -->
<div class="quarto-navbar-tools">
</div>
</div> <!-- /container-fluid -->
</nav>
</header>
<!-- content -->
<header id="title-block-header" class="quarto-title-block default page-columns page-full">
<div class="quarto-title-banner page-columns page-full">
<div class="quarto-title column-body">
<h1 class="title">Faire une CI LaTeX avec GitLab</h1>
<div class="quarto-categories">
<div class="quarto-category">ci</div>
<div class="quarto-category">intégration continue</div>
<div class="quarto-category">git</div>
<div class="quarto-category">GitLab</div>
<div class="quarto-category">LaTeX</div>
<div class="quarto-category">french</div>
<div class="quarto-category">français</div>
</div>
</div>
</div>
<div class="quarto-title-meta-author">
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-heading">Affiliation</div>
<div class="quarto-title-meta-contents">
<p class="author">Louis Lacoste <a href="mailto:louis.lacoste@agroparistech.fr" class="quarto-title-author-email"><i class="bi bi-envelope"></i></a> <a href="https://orcid.org/0009-0004-0178-9821" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a></p>
</div>
<div class="quarto-title-meta-contents">
<p class="affiliation">
MIA Paris-Saclay, INRAE, AgroParisTech, Université Paris-Saclay
</p>
</div>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">September 23, 2025</p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Modified</div>
<div class="quarto-title-meta-contents">
<p class="date-modified">March 26, 2026</p>
</div>
</div>
</div>
</header><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">On this page</h2>
<ul>
<li><a href="#the-final-ci" id="toc-the-final-ci" class="nav-link active" data-scroll-target="#the-final-ci">The Final CI</a></li>
<li><a href="#variables" id="toc-variables" class="nav-link" data-scroll-target="#variables">Variables</a></li>
<li><a href="#the-steps" id="toc-the-steps" class="nav-link" data-scroll-target="#the-steps">The Steps</a>
<ul class="collapse">
<li><a href="#the-compilation-phase-build_tex" id="toc-the-compilation-phase-build_tex" class="nav-link" data-scroll-target="#the-compilation-phase-build_tex">The compilation phase <code>build_tex</code></a></li>
<li><a href="#the-deployment-phase-deploy" id="toc-the-deployment-phase-deploy" class="nav-link" data-scroll-target="#the-deployment-phase-deploy">The deployment phase <code>deploy</code></a></li>
</ul></li>
</ul>
</nav>
</div>
<!-- main -->
<main class="content quarto-banner-title-block" id="quarto-document-content">
<p><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><button onclick="window.location = '/fr' + location.pathname;" class="btn"><i class="fa fa-language"></i> Français </button></p>
<section id="the-final-ci" class="level1">
<h1>The Final CI</h1>
<p>Here is the content of one of my <code>.gitlab-ci.yaml</code> files</p>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important
</div>
</div>
<div class="callout-body-container callout-body">
<p>If you see any inconsistencies, contact me by email: <a href="mailto:louis.lacoste@agroparistech.fr">louis.lacoste@agroparistech.fr</a></p>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><a href="#cb1-1"></a><span class="fu">variables</span><span class="kw">:</span></span>
<span id="cb1-2"><a href="#cb1-2"></a><span class="co"> # Version de git utilisée</span></span>
<span id="cb1-3"><a href="#cb1-3"></a><span class="at"> </span><span class="fu">GIT_VERSION</span><span class="kw">:</span><span class="at"> v2.30.1</span></span>
<span id="cb1-4"><a href="#cb1-4"></a></span>
<span id="cb1-5"><a href="#cb1-5"></a><span class="co"> # Branche cible pour les PDF (modifiable via CI/CD variables)</span></span>
<span id="cb1-6"><a href="#cb1-6"></a><span class="at"> </span><span class="fu">PDF_BRANCH</span><span class="kw">:</span><span class="at"> </span><span class="st">"pdf"</span></span>
<span id="cb1-7"><a href="#cb1-7"></a></span>
<span id="cb1-8"><a href="#cb1-8"></a><span class="at"> </span><span class="fu">FILE_NAMES</span><span class="kw">:</span><span class="at"> 2024-2025-rapport-csi 2024-2025-presentation-csi</span></span>
<span id="cb1-9"><a href="#cb1-9"></a></span>
<span id="cb1-10"><a href="#cb1-10"></a><span class="fu">build_tex</span><span class="kw">:</span></span>
<span id="cb1-11"><a href="#cb1-11"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> build</span></span>
<span id="cb1-12"><a href="#cb1-12"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span><span class="at"> danteev/texlive:latest</span><span class="co"> # texlive plus inkscape and others</span></span>
<span id="cb1-13"><a href="#cb1-13"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb1-14"><a href="#cb1-14"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb1-15"><a href="#cb1-15"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb1-16"><a href="#cb1-16"></a> do</span>
<span id="cb1-17"><a href="#cb1-17"></a> echo "Compiling ${FILE_NAME}"</span>
<span id="cb1-18"><a href="#cb1-18"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb1-19"><a href="#cb1-19"></a> if test -f ${FILE_NAME}.bcf; then</span>
<span id="cb1-20"><a href="#cb1-20"></a> echo "Found ${FILE_NAME}.bcf, running biber"</span>
<span id="cb1-21"><a href="#cb1-21"></a> biber ${FILE_NAME}</span>
<span id="cb1-22"><a href="#cb1-22"></a> fi</span>
<span id="cb1-23"><a href="#cb1-23"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb1-24"><a href="#cb1-24"></a> done</span>
<span id="cb1-25"><a href="#cb1-25"></a><span class="at"> </span><span class="fu">after_script</span><span class="kw">:</span></span>
<span id="cb1-26"><a href="#cb1-26"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb1-27"><a href="#cb1-27"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb1-28"><a href="#cb1-28"></a> do</span>
<span id="cb1-29"><a href="#cb1-29"></a> echo "============================================"</span>
<span id="cb1-30"><a href="#cb1-30"></a> cat ${FILE_NAME}.log</span>
<span id="cb1-31"><a href="#cb1-31"></a> echo "============================================"</span>
<span id="cb1-32"><a href="#cb1-32"></a> done</span>
<span id="cb1-33"><a href="#cb1-33"></a></span>
<span id="cb1-34"><a href="#cb1-34"></a><span class="at"> </span><span class="fu">artifacts</span><span class="kw">:</span></span>
<span id="cb1-35"><a href="#cb1-35"></a><span class="at"> </span><span class="fu">paths</span><span class="kw">:</span></span>
<span id="cb1-36"><a href="#cb1-36"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="st">"*.pdf"</span></span>
<span id="cb1-37"><a href="#cb1-37"></a><span class="fu">deploy</span><span class="kw">:</span></span>
<span id="cb1-38"><a href="#cb1-38"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> deploy</span></span>
<span id="cb1-39"><a href="#cb1-39"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span></span>
<span id="cb1-40"><a href="#cb1-40"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> alpine/git:${GIT_VERSION}</span></span>
<span id="cb1-41"><a href="#cb1-41"></a><span class="at"> </span><span class="fu">entrypoint</span><span class="kw">:</span><span class="at"> </span><span class="kw">[</span><span class="st">""</span><span class="kw">]</span></span>
<span id="cb1-42"><a href="#cb1-42"></a></span>
<span id="cb1-43"><a href="#cb1-43"></a><span class="at"> </span><span class="fu">before_script</span><span class="kw">:</span></span>
<span id="cb1-44"><a href="#cb1-44"></a><span class="co"> # Clone le repo dans un dossier temporaire</span></span>
<span id="cb1-45"><a href="#cb1-45"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git clone "https://${GITLAB_USERNAME}:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "${CI_COMMIT_SHA}"</span></span>
<span id="cb1-46"><a href="#cb1-46"></a></span>
<span id="cb1-47"><a href="#cb1-47"></a><span class="co"> # Configure lidentité git</span></span>
<span id="cb1-48"><a href="#cb1-48"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}"</span></span>
<span id="cb1-49"><a href="#cb1-49"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.name "${GIT_USER_NAME:-$GITLAB_USER_NAME}"</span></span>
<span id="cb1-50"><a href="#cb1-50"></a></span>
<span id="cb1-51"><a href="#cb1-51"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb1-52"><a href="#cb1-52"></a><span class="co"> # Déplace les PDFs compilés dans le repo cloné</span></span>
<span id="cb1-53"><a href="#cb1-53"></a><span class="at"> </span><span class="kw">-</span><span class="at"> mv *.pdf "${CI_COMMIT_SHA}/"</span></span>
<span id="cb1-54"><a href="#cb1-54"></a><span class="at"> </span><span class="kw">-</span><span class="at"> cd "${CI_COMMIT_SHA}"</span></span>
<span id="cb1-55"><a href="#cb1-55"></a></span>
<span id="cb1-56"><a href="#cb1-56"></a><span class="co"> # Crée une branche orpheline (vierge, sans historique ni fichiers)</span></span>
<span id="cb1-57"><a href="#cb1-57"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git checkout --orphan "${PDF_BRANCH}"</span></span>
<span id="cb1-58"><a href="#cb1-58"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git reset --hard</span></span>
<span id="cb1-59"><a href="#cb1-59"></a></span>
<span id="cb1-60"><a href="#cb1-60"></a><span class="co"> # Ajoute uniquement les PDF</span></span>
<span id="cb1-61"><a href="#cb1-61"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git add -f *.pdf</span></span>
<span id="cb1-62"><a href="#cb1-62"></a></span>
<span id="cb1-63"><a href="#cb1-63"></a><span class="co"> # Vérifie sil y a des changements et push</span></span>
<span id="cb1-64"><a href="#cb1-64"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb1-65"><a href="#cb1-65"></a> CHANGES=$(git status --porcelain | wc -l)</span>
<span id="cb1-66"><a href="#cb1-66"></a> if [ "$CHANGES" -gt "0" ]; then</span>
<span id="cb1-67"><a href="#cb1-67"></a> git commit -m "${COMMIT_MESSAGE:-Updating PDF files}"</span>
<span id="cb1-68"><a href="#cb1-68"></a> git push --force origin "${PDF_BRANCH}" -o ci.skip</span>
<span id="cb1-69"><a href="#cb1-69"></a> else</span>
<span id="cb1-70"><a href="#cb1-70"></a> echo "No PDF changes to commit"</span>
<span id="cb1-71"><a href="#cb1-71"></a> fi</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Lets break down what happens!</p>
</section>
<section id="variables" class="level1">
<h1>Variables</h1>
<p>The variables section below is used to define variables that we will reference later.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb2-1"><a href="#cb2-1"></a><span class="fu">variables</span><span class="kw">:</span></span>
<span id="cb2-2"><a href="#cb2-2"></a><span class="co"> # Version de git utilisée</span></span>
<span id="cb2-3"><a href="#cb2-3"></a><span class="at"> </span><span class="fu">GIT_VERSION</span><span class="kw">:</span><span class="at"> v2.30.1</span></span>
<span id="cb2-4"><a href="#cb2-4"></a></span>
<span id="cb2-5"><a href="#cb2-5"></a><span class="co"> # Branche cible pour les PDF (modifiable via CI/CD variables)</span></span>
<span id="cb2-6"><a href="#cb2-6"></a><span class="at"> </span><span class="fu">PDF_BRANCH</span><span class="kw">:</span><span class="at"> </span><span class="st">"pdf"</span></span>
<span id="cb2-7"><a href="#cb2-7"></a></span>
<span id="cb2-8"><a href="#cb2-8"></a><span class="at"> </span><span class="fu">FILE_NAMES</span><span class="kw">:</span><span class="at"> 2024-2025-rapport-csi 2024-2025-presentation-csi</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ul>
<li><code>GIT_VERSION</code>: specifies the git version to use for the Docker image were going to fetch.</li>
<li><code>PDF_BRANCH</code>: indicates the name of the branch on which our PDFs will be published.</li>
<li><code>FILE_NAMES</code>: declares the list of file names (without extensions). In yaml format, these are strings without quotes separated by spaces</li>
</ul>
</section>
<section id="the-steps" class="level1">
<h1>The Steps</h1>
<section id="the-compilation-phase-build_tex" class="level2">
<h2 class="anchored" data-anchor-id="the-compilation-phase-build_tex">The compilation phase <code>build_tex</code></h2>
<p>Lets detail the <code>build_tex</code> step:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><a href="#cb3-1"></a><span class="fu">build_tex</span><span class="kw">:</span></span>
<span id="cb3-2"><a href="#cb3-2"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> build</span></span>
<span id="cb3-3"><a href="#cb3-3"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span><span class="at"> danteev/texlive:latest</span><span class="co"> # texlive plus inkscape and others</span></span>
<span id="cb3-4"><a href="#cb3-4"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb3-5"><a href="#cb3-5"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb3-6"><a href="#cb3-6"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb3-7"><a href="#cb3-7"></a> do</span>
<span id="cb3-8"><a href="#cb3-8"></a> echo "Compiling ${FILE_NAME}"</span>
<span id="cb3-9"><a href="#cb3-9"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb3-10"><a href="#cb3-10"></a> if test -f ${FILE_NAME}.bcf; then</span>
<span id="cb3-11"><a href="#cb3-11"></a> echo "Found ${FILE_NAME}.bcf, running biber"</span>
<span id="cb3-12"><a href="#cb3-12"></a> biber ${FILE_NAME}</span>
<span id="cb3-13"><a href="#cb3-13"></a> fi</span>
<span id="cb3-14"><a href="#cb3-14"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb3-15"><a href="#cb3-15"></a> done</span>
<span id="cb3-16"><a href="#cb3-16"></a><span class="at"> </span><span class="fu">after_script</span><span class="kw">:</span></span>
<span id="cb3-17"><a href="#cb3-17"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb3-18"><a href="#cb3-18"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb3-19"><a href="#cb3-19"></a> do</span>
<span id="cb3-20"><a href="#cb3-20"></a> echo "============================================"</span>
<span id="cb3-21"><a href="#cb3-21"></a> cat ${FILE_NAME}.log</span>
<span id="cb3-22"><a href="#cb3-22"></a> echo "============================================"</span>
<span id="cb3-23"><a href="#cb3-23"></a> done</span>
<span id="cb3-24"><a href="#cb3-24"></a></span>
<span id="cb3-25"><a href="#cb3-25"></a><span class="at"> </span><span class="fu">artifacts</span><span class="kw">:</span></span>
<span id="cb3-26"><a href="#cb3-26"></a><span class="at"> </span><span class="fu">paths</span><span class="kw">:</span></span>
<span id="cb3-27"><a href="#cb3-27"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="st">"*.pdf"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>First, we declare <code>stage: build</code> to qualify the step were performing here. There are 3 possible stages: <code>build, test, deploy</code> (<a href="https://docs.gitlab.com/ci/yaml/#stage">GitLab documentation</a>). Here we choose <code>build</code> since this is the compilation of our project.</p>
<p>Next, we load a docker image that contains the <code>texlive</code> tools.</p>
<p>Finally, the <code>script</code> directive defines in <code>bash</code> the sequence of steps we perform to compile the project.</p>
<div class="callout callout-style-default callout-note callout-titled" title="Conditional execution of `biber`">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Conditional execution of <code>biber</code>
</div>
</div>
<div class="callout-body-container callout-body">
<p>Note that we havent included extensions in <code>FILE_NAMES</code> so that we can detect here the bcf files characteristic of the bibliography.</p>
</div>
</div>
<p>Finally, we use the <code>after_script</code> directive to display the compilation log files in the CI logs.</p>
<p>Lastly, <code>artifacts</code> specifies that the artifacts we want to keep from the CI are all PDFs at the root of the repository</p>
</section>
<section id="the-deployment-phase-deploy" class="level2">
<h2 class="anchored" data-anchor-id="the-deployment-phase-deploy">The deployment phase <code>deploy</code></h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb4-1"><a href="#cb4-1"></a><span class="fu">deploy</span><span class="kw">:</span></span>
<span id="cb4-2"><a href="#cb4-2"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> deploy</span></span>
<span id="cb4-3"><a href="#cb4-3"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span></span>
<span id="cb4-4"><a href="#cb4-4"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> alpine/git:${GIT_VERSION}</span></span>
<span id="cb4-5"><a href="#cb4-5"></a><span class="at"> </span><span class="fu">entrypoint</span><span class="kw">:</span><span class="at"> </span><span class="kw">[</span><span class="st">""</span><span class="kw">]</span></span>
<span id="cb4-6"><a href="#cb4-6"></a></span>
<span id="cb4-7"><a href="#cb4-7"></a><span class="at"> </span><span class="fu">before_script</span><span class="kw">:</span></span>
<span id="cb4-8"><a href="#cb4-8"></a><span class="co"> # Clone le repo dans un dossier temporaire</span></span>
<span id="cb4-9"><a href="#cb4-9"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git clone "https://${GITLAB_USERNAME}:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "${CI_COMMIT_SHA}"</span></span>
<span id="cb4-10"><a href="#cb4-10"></a></span>
<span id="cb4-11"><a href="#cb4-11"></a><span class="co"> # Configure lidentité git</span></span>
<span id="cb4-12"><a href="#cb4-12"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}"</span></span>
<span id="cb4-13"><a href="#cb4-13"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.name "${GIT_USER_NAME:-$GITLAB_USER_NAME}"</span></span>
<span id="cb4-14"><a href="#cb4-14"></a></span>
<span id="cb4-15"><a href="#cb4-15"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb4-16"><a href="#cb4-16"></a><span class="co"> # Déplace les PDFs compilés dans le repo cloné</span></span>
<span id="cb4-17"><a href="#cb4-17"></a><span class="at"> </span><span class="kw">-</span><span class="at"> mv *.pdf "${CI_COMMIT_SHA}/"</span></span>
<span id="cb4-18"><a href="#cb4-18"></a><span class="at"> </span><span class="kw">-</span><span class="at"> cd "${CI_COMMIT_SHA}"</span></span>
<span id="cb4-19"><a href="#cb4-19"></a></span>
<span id="cb4-20"><a href="#cb4-20"></a><span class="co"> # Crée une branche orpheline (vierge, sans historique ni fichiers)</span></span>
<span id="cb4-21"><a href="#cb4-21"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git checkout --orphan "${PDF_BRANCH}"</span></span>
<span id="cb4-22"><a href="#cb4-22"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git reset --hard</span></span>
<span id="cb4-23"><a href="#cb4-23"></a></span>
<span id="cb4-24"><a href="#cb4-24"></a><span class="co"> # Ajoute uniquement les PDF</span></span>
<span id="cb4-25"><a href="#cb4-25"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git add -f *.pdf</span></span>
<span id="cb4-26"><a href="#cb4-26"></a></span>
<span id="cb4-27"><a href="#cb4-27"></a><span class="co"> # Vérifie sil y a des changements et push</span></span>
<span id="cb4-28"><a href="#cb4-28"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb4-29"><a href="#cb4-29"></a> CHANGES=$(git status --porcelain | wc -l)</span>
<span id="cb4-30"><a href="#cb4-30"></a> if [ "$CHANGES" -gt "0" ]; then</span>
<span id="cb4-31"><a href="#cb4-31"></a> git commit -m "${COMMIT_MESSAGE:-Updating PDF files}"</span>
<span id="cb4-32"><a href="#cb4-32"></a> git push --force origin "${PDF_BRANCH}" -o ci.skip</span>
<span id="cb4-33"><a href="#cb4-33"></a> else</span>
<span id="cb4-34"><a href="#cb4-34"></a> echo "No PDF changes to commit"</span>
<span id="cb4-35"><a href="#cb4-35"></a> fi</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Finally, we deploy our PDFs. For this, we load a lightweight <code>Alpine Linux</code> image with the Git version selected in the variables.</p>
<p>With the <code>before_script</code> directive, we clone the repository.</p>
<div class="callout callout-style-default callout-important callout-titled" title="To create the GitLab token">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
To create the GitLab token
</div>
</div>
<div class="callout-body-container callout-body">
<p>Note in the <code>git clone</code> that we use a <code>GITLAB_TOKEN</code> variable, which must be created beforehand and declared in the repository.</p>
<p>To do this:</p>
<ol type="1">
<li>Go to your repository settings.</li>
</ol>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="resources/ci-gitlab-latex/access-token-settings.png" class="img-fluid figure-img"></p>
<figcaption>In the left menus, expand “Settings” and go to “Access tokens”</figcaption>
</figure>
</div>
<ol start="2" type="1">
<li>Here add a new token.</li>
</ol>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="resources/ci-gitlab-latex/add-new-token.png" class="img-fluid figure-img"></p>
<figcaption>Click on “Add new token”</figcaption>
</figure>
</div>
<ol start="3" type="1">
<li>Configure the <code>read_repository</code> and <code>write_repository</code> permissions to be able to clone and push our files. Then click on “Create project access token”.</li>
</ol>
<p><img src="resources/ci-gitlab-latex/scope.png" class="img-fluid"></p>
<ol start="4" type="1">
<li><p>Your token is now displayed, copy it as it will not be displayed again.</p></li>
<li><p>Now go to CI/CD settings.</p></li>
</ol>
<p><img src="resources/ci-gitlab-latex/ci-settings.png" class="img-fluid"></p>
<ol start="6" type="1">
<li>Now create the variable by clicking on “Add variable”, name it <code>GITLAB_TOKEN</code>, in “value” add the copied token.</li>
</ol>
</div>
</div>
<p>The rest of the script moves the PDFs to the cloned repository, creates the publication branch and adds the pdfs.</p>
<p>You should now have a CI for compiling and publishing PDFs! Now you can reference your PDFs in your <code>README.md</code> by entering a link like:</p>
<p><code>https://mygitlab.com/myusername/myrepo/-/raw/mypdf.pdf</code></p>
<p>which allows you to display the compilation output directly in the browser. 😄</p>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
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) {
// 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 codeEl = trigger.previousElementSibling.cloneNode(true);
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<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// undo the damage that might have been done by quarto-nav.js in the case of
// links that we want to consider external
if (link.dataset.originalHref !== undefined) {
link.href = link.dataset.originalHref;
}
}
}
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);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note) {
return note.innerHTML;
} else {
return "";
}
});
}
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<xrefs.length; i++) {
const xref = xrefs[i];
tippyHover(xref, undefined, function(instance) {
instance.disable();
let url = xref.getAttribute('href');
let hash = undefined;
if (url.startsWith('#')) {
hash = url;
} else {
try { hash = new URL(url).hash; } catch {}
}
if (hash) {
const id = hash.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note !== null) {
try {
const html = processXRef(id, note.cloneNode(true));
instance.setContent(html);
} finally {
instance.enable();
instance.show();
}
} else {
// See if we can fetch this
fetch(url.split('#')[0])
.then(res => 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';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
div.style.left = 0;
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
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();
}
});
selectedAnnoteEl = undefined;
};
// Handle positioning of the toggle
window.addEventListener(
"resize",
throttle(() => {
elRect = undefined;
if (selectedAnnoteEl) {
selectCodeLines(selectedAnnoteEl);
}
}, 10)
);
function throttle(fn, ms) {
let throttle = false;
let timer;
return (...args) => {
if(!throttle) { // first call gets through
fn.apply(this, args);
throttle = true;
} else { // all the others get throttled
if(timer) clearTimeout(timer); // cancel #2
timer = setTimeout(() => {
fn.apply(this, args);
timer = throttle = false;
}, ms);
}
};
}
// Attach click handler to the DT
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 {
// Unselect the line
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<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;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>