her.esy.fun/src/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/index.html
Yann Esposito (Yogsototh) 059fabd7d0
many minor details to update
2022-10-26 11:38:50 +02:00

146 lines
11 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 lang="fr">
<head>
<meta charset="utf-8">
<title>YBlog - Des macros LaTeX pour markdown</title>
<meta name="keywords" content="LaTeX, macros, markdown, nanoc, ruby" />
<link rel="shortcut icon" type="image/x-icon" href="../../../../Scratch/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../../../css/y.css" />
<link rel="stylesheet" type="text/css" href="/css/legacy.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="../../../../Scratch/img/about/FlatAvatar@2x.png" />
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<!-- IndieAuth -->
<link href="https://twitter.com/yogsototh" rel="me">
<link href="https://github.com/yogsototh" rel="me">
<link href="mailto:yann.esposito@gmail.com" rel="me">
<link rel="pgpkey" href="../../../../pubkey.txt">
</head>
<body lang="fr" class="article">
<div id="content">
<div id="header">
<div id="choix">
<span id="choixlang">
<a href="../../../../Scratch/en/blog/2010-10-26-LaTeX-like-macro-and-markdown/">Anglais</a>
</span>
<span class="tomenu"><a href="#navigation">↓ Menu ↓</a></span>
<span class="flush"></span>
</div>
</div>
<div id="titre">
<h1>Des macros LaTeX pour markdown</h1>
</div>
<div class="flush"></div>
<div id="afterheader" class="article">
<div class="corps">
<div class="intro">
<p><span class="sc"><abbr title="Trop long; pas lu">tlpl</abbr>: </span> Jai fait un système simple de macros pour mon blog. Par exemple, il me suffit décrire %<span></span>latex et ça affiche <span style="text-transform: uppercase">L<sup style="vertical-align: 0.15em; margin-left: -0.36em; margin-right: -0.15em; font-size: .85em">a</sup>T<sub style="vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em; font-size: 1em">e</sub>X</span>.</p>
</div>
<p>Jai ajouter un système de macro pour mon système de blog. Lorsquon est habitué à <span style="text-transform: uppercase">L<sup style="vertical-align: 0.15em; margin-left: -0.36em; margin-right: -0.15em; font-size: .85em">a</sup>T<sub style="vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em; font-size: 1em">e</sub>X</span> et que lon commence à écrire des articles un peu conséquent avec des notations mathématiques, les macros deviennent vite quelque chose dindispensable.</p>
<p>Dans lentête de mes fichiers jécris simplement:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode yaml"><code class="sourceCode yaml"></code></pre></div>
<p>Puis dans le corps ça va remplacer&nbsp;:</p>
<ul>
<li>%<span></span>test par <em>Just a test</em> ;</li>
<li>et %<span></span>latex par <em><span style="text-transform: uppercase">L<sup style="vertical-align: 0.15em; margin-left: -0.36em; margin-right: -0.15em; font-size: .85em">a</sup>T<sub style="vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em; font-size: 1em">e</sub>X</span></em></li>
</ul>
<p>Le code est assez simple. Pour les utilisateurs de <code>nanoc</code> il suffit de copier le fichier suivant dans le répertoire <code>lib</code>.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode ruby"><code class="sourceCode ruby"><a class="sourceLine" id="cb2-1" title="1"><span class="co"># usage:</span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="co"># ---</span></a>
<a class="sourceLine" id="cb2-3" title="3"><span class="co"># ...</span></a>
<a class="sourceLine" id="cb2-4" title="4"><span class="co"># macros:</span></a>
<a class="sourceLine" id="cb2-5" title="5"><span class="co"># test: &quot;passed test&quot;</span></a>
<a class="sourceLine" id="cb2-6" title="6"><span class="co"># ---</span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="co"># ...</span></a>
<a class="sourceLine" id="cb2-8" title="8"><span class="co"># Here is a Just a test.</span></a>
<a class="sourceLine" id="cb2-9" title="9"><span class="co">#</span></a>
<a class="sourceLine" id="cb2-10" title="10"><span class="kw">class</span> <span class="dt">Macros</span> &lt; <span class="dt">Nanoc3</span>::<span class="dt">Filter</span></a>
<a class="sourceLine" id="cb2-11" title="11"> identifier <span class="st">:falacy</span></a>
<a class="sourceLine" id="cb2-12" title="12"> <span class="ot">attr_accessor</span> <span class="st">:macro</span></a>
<a class="sourceLine" id="cb2-13" title="13"> <span class="kw">def</span> initialize(arg)</a>
<a class="sourceLine" id="cb2-14" title="14"> <span class="dv">super</span></a>
<a class="sourceLine" id="cb2-15" title="15"> <span class="ot">@macro</span>={}</a>
<a class="sourceLine" id="cb2-16" title="16"> <span class="ot">@macro</span>[<span class="st">:tlal</span>] =<span class="ot"> %{</span><span class="st">&lt;span class=&quot;sc&quot;&gt;&lt;abbr title=&quot;Trop long à lire&quot;&gt;tlàl&lt;/abbr&gt; : &lt;/span&gt;</span><span class="ot">}</span></a>
<a class="sourceLine" id="cb2-17" title="17"> <span class="ot">@macro</span>[<span class="st">:tldr</span>] =<span class="ot"> %{</span><span class="st">&lt;span class=&quot;sc&quot;&gt;&lt;abbr title=&quot;Too long; didn't read&quot;&gt;tl;dr&lt;/abbr&gt;: &lt;/span&gt;</span><span class="ot">}</span></a>
<a class="sourceLine" id="cb2-18" title="18"> <span class="kw">if</span> <span class="ot">@item</span>.nil?</a>
<a class="sourceLine" id="cb2-19" title="19"> <span class="kw">if</span> <span class="kw">not</span> arg.nil?</a>
<a class="sourceLine" id="cb2-20" title="20"> <span class="ot">@macro</span>.merge!( arg )</a>
<a class="sourceLine" id="cb2-21" title="21"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-22" title="22"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb2-23" title="23"> <span class="kw">if</span> <span class="kw">not</span> <span class="ot">@item</span>[<span class="st">:macros</span>].nil?</a>
<a class="sourceLine" id="cb2-24" title="24"> <span class="ot">@macro</span>.merge!( <span class="ot">@item</span>[<span class="st">:macros</span>] )</a>
<a class="sourceLine" id="cb2-25" title="25"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-26" title="26"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-27" title="27"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-28" title="28"> <span class="kw">def</span> macro_value_for(macro_name)</a>
<a class="sourceLine" id="cb2-29" title="29"> <span class="kw">if</span> macro_name.nil? <span class="kw">or</span> macro_name==<span class="st">&quot;&quot;</span> <span class="kw">or</span> <span class="ot">@macro</span>[macro_name.intern].nil?</a>
<a class="sourceLine" id="cb2-30" title="30"> <span class="kw">return</span><span class="ot"> %{</span><span class="st">%</span><span class="ot">#{</span>macro_name<span class="ot">}}</span> </a>
<a class="sourceLine" id="cb2-31" title="31"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-32" title="32"> <span class="kw">return</span> <span class="ot">@macro</span>[macro_name.intern]</a>
<a class="sourceLine" id="cb2-33" title="33"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-34" title="34"> <span class="kw">def</span> run(content, params={})</a>
<a class="sourceLine" id="cb2-35" title="35"> content.gsub(<span class="ot">/%(\w*)/</span>) <span class="kw">do</span> |m| </a>
<a class="sourceLine" id="cb2-36" title="36"> <span class="kw">if</span> m != <span class="ch">'%'</span></a>
<a class="sourceLine" id="cb2-37" title="37"> macro_value_for(<span class="dt">$1</span>)</a>
<a class="sourceLine" id="cb2-38" title="38"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb2-39" title="39"> m</a>
<a class="sourceLine" id="cb2-40" title="40"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-41" title="41"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-42" title="42"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb2-43" title="43"><span class="kw">end</span></a></code></pre></div>
<p>Les macros peuvent être vraiment utiles. Lisez <a href="http://adam.gomaa.us/blog/2007/oct/22/markdown-doesnt-scale/index.html">cet article</a> par exemple.</p>
</div>
<div id="afterarticle">
<div id="social">
<a href="/rss.xml" target="_blank" rel="noopener noreferrer nofollow" class="social">RSS</a>
·
<a href="https://twitter.com/home?status=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/%20via%20@yogsototh" target="_blank" rel="noopener noreferrer nofollow" class="social">Tweet</a>
·
<a href="http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/" target="_blank" rel="noopener noreferrer nofollow" class="social">FB</a>
<br />
<a class="message" href="../../../../Scratch/fr/blog/Social-link-the-right-way/">Ces liens sociaux préservent votre vie privée</a>
</div>
<div id="navigation">
<a href="../../../../">Accueil</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/blog">Blog</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/softwares">Logiciels</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/about">Auteur</a>
</div>
<div id="totop"><a href="#header">↑ Top ↑</a></div>
<div id="bottom">
<div>
Published on 2010-10-26
</div>
<div>
<a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
</div>
<div>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Yann Esposito©</a>
</div>
<div>
Done with
<a href="http://www.vim.org" target="_blank" rel="noopener noreferrer nofollow"><strike>Vim</strike></a>
<a href="http://spacemacs.org" target="_blank" rel="noopener noreferrer nofollow">spacemacs</a>
<span class="pala">&amp;</span>
<a href="http://nanoc.ws" target="_blank" rel="noopener noreferrer nofollow"><strike>nanoc</strike></a>
<a href="http://jaspervdj.be/hakyll" target="_blank" rel="noopener noreferrer nofollow">Hakyll</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>