scratch/output/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/index.html

256 lines
16 KiB
HTML
Raw Normal View History

2011-04-20 12:29:01 +00:00
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
2011-10-26 08:49:00 +00:00
<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="/Scratch/assets/css/main.css" />
<link rel="stylesheet" type="text/css" href="/Scratch/css/twilight.css" />
<link rel="stylesheet" type="text/css" href="/Scratch/css/idc.css" />
2011-04-20 12:29:01 +00:00
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.com/yannespositocomfr"/>
<link rel="alternate" lang="fr" xml:lang="fr" title="Des macros LaTeX pour markdown" type="text/html" hreflang="fr" href="/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/" />
<link rel="alternate" lang="en" xml:lang="en" title="LaTeX like macro for markdown" type="text/html" hreflang="en" href="/Scratch/en/blog/2010-10-26-LaTeX-like-macro-and-markdown/" />
<script type="text/javascript" src="/Scratch/js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="/Scratch/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/Scratch/js/index.js"></script>
2011-04-20 12:29:01 +00:00
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<title>Des macros LaTeX pour markdown</title>
</head>
2011-10-18 22:30:00 +00:00
<body lang="fr" class="article">
2011-04-20 12:29:01 +00:00
<script type="text/javascript">// <![CDATA[
document.write('<div id="blackpage"><img src="/Scratch/img/loading.gif" alt="Chargement en cours..."/></div>');
2011-04-20 12:29:01 +00:00
// ]]>
</script>
<div id="content">
<div id="choix">
<div class="return"><a href="#entete">&darr; Menu &darr;</a></div>
<div id="choixlang">
<a href="/Scratch/en/blog/2010-10-26-LaTeX-like-macro-and-markdown/" onclick="setLanguage('en')">in English</a>
2011-04-20 12:29:01 +00:00
</div>
2011-09-28 16:05:55 +00:00
<div class="flush"></div>
2011-04-20 12:29:01 +00:00
</div>
<div id="titre">
<h1>
Des macros LaTeX pour markdown
</h1>
</div>
<div class="flush"></div>
<div class="flush"></div>
<div id="afterheader">
<div class="corps">
<div class="intro">
2012-01-18 14:51:20 +00:00
<p><span class="sc"><abbr title="Trop long à lire">tlàl</abbr>&nbsp;: </span> J&rsquo;ai fait un système simple de macros pour mon blog. Par exemple, il me suffit d&rsquo;é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>
2011-04-20 12:29:01 +00:00
</div>
2011-12-07 16:37:23 +00:00
<p>J&rsquo;ai ajouter un système de macro pour mon système de blog.
Lorsqu&rsquo;on 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 l&rsquo;on commence à écrire des articles
2011-04-20 12:29:01 +00:00
un peu conséquent avec des notations mathématiques,
2011-12-07 16:37:23 +00:00
les macros deviennent vite quelque chose d&rsquo;indispensable.</p>
2011-04-20 12:29:01 +00:00
2011-12-07 16:37:23 +00:00
<p>Dans l&rsquo;entête de mes fichiers j&rsquo;écris simplement:</p>
2011-04-20 12:29:01 +00:00
<pre class="twilight">
<span class="MetaTagAll"><span class="MetaTagInline">macros</span><span class="MetaTagAll">:</span></span>
<span class="MetaTagAll"><span class="MetaTagInline">test</span><span class="MetaTagAll">:</span> </span><span class="String"><span class="String">&quot;</span>This is a macro test<span class="String">&quot;</span></span>
<span class="MetaTagAll"><span class="MetaTagInline">latex</span><span class="MetaTagAll">:</span> </span><span class="String"><span class="String">'</span>&lt;span style=&quot;text-transform: uppercase&quot;&gt;L&lt;sup style=&quot;vertical-align: 0.15em; margin-left: -0.36em; margin-right: -0.15em; font-size: .85em&quot;&gt;a&lt;/sup&gt;T&lt;sub style=&quot;vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em; font-size: 1em&quot;&gt;e&lt;/sub&gt;X&lt;/span&gt;<span class="String">'</span></span>
</pre>
<p>Puis dans le corps ça va remplacer&nbsp;:</p>
<ul>
2012-01-18 14:51:20 +00:00
<li>%<span></span>test par <em>This is a macro test</em>&nbsp;;</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>
2011-04-20 12:29:01 +00:00
</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="code"><div class="file"><a href="/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/code/macros.rb"> &#x27A5; macros.rb </a></div><div class="withfile">
2011-04-20 12:29:01 +00:00
<pre class="twilight">
<span class="Comment"><span class="Comment">#</span> usage:</span>
<span class="Comment"><span class="Comment">#</span> ---</span>
<span class="Comment"><span class="Comment">#</span> ...</span>
<span class="Comment"><span class="Comment">#</span> macros:</span>
<span class="Comment"><span class="Comment">#</span> test: &quot;passed test&quot;</span>
<span class="Comment"><span class="Comment">#</span> ---</span>
<span class="Comment"><span class="Comment">#</span> ...</span>
<span class="Comment"><span class="Comment">#</span> Here is a This is a macro test.</span>
<span class="Comment"><span class="Comment">#</span></span>
<span class="Keyword">class</span> <span class="Entity">Macros<span class="EntityInheritedClass"> <span class="EntityInheritedClass">&lt;</span> Nanoc3::Filter</span></span>
identifier <span class="Constant"><span class="Constant">:</span>falacy</span>
<span class="Keyword">attr_accessor</span> <span class="Constant"><span class="Constant">:</span>macro</span>
<span class="Keyword">def</span> <span class="Entity">initialize</span>(<span class="Variable">arg</span>)
<span class="Keyword">super</span>
<span class="Variable"><span class="Variable">@</span>macro</span><span class="Keyword">=</span>{}
2012-01-11 20:40:22 +00:00
<span class="Variable"><span class="Variable">@</span>macro</span>[<span class="Constant"><span class="Constant">:</span>tlal</span>] <span class="Keyword">=</span> <span class="String"><span class="String">%{</span>&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 class="String">}</span></span>
2011-09-02 11:40:34 +00:00
<span class="Variable"><span class="Variable">@</span>macro</span>[<span class="Constant"><span class="Constant">:</span>tldr</span>] <span class="Keyword">=</span> <span class="String"><span class="String">%{</span>&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 class="String">}</span></span>
2011-04-20 12:29:01 +00:00
<span class="Keyword">if</span> <span class="Variable"><span class="Variable">@</span>item</span>.<span class="Entity">nil?</span>
<span class="Keyword">if</span> <span class="Keyword">not</span> arg.<span class="Entity">nil?</span>
<span class="Variable"><span class="Variable">@</span>macro</span>.<span class="Entity">merge!</span>( arg )
<span class="Keyword">end</span>
<span class="Keyword">else</span>
<span class="Keyword">if</span> <span class="Keyword">not</span> <span class="Variable"><span class="Variable">@</span>item</span>[<span class="Constant"><span class="Constant">:</span>macros</span>].<span class="Entity">nil?</span>
<span class="Variable"><span class="Variable">@</span>macro</span>.<span class="Entity">merge!</span>( <span class="Variable"><span class="Variable">@</span>item</span>[<span class="Constant"><span class="Constant">:</span>macros</span>] )
<span class="Keyword">end</span>
<span class="Keyword">end</span>
<span class="Keyword">end</span>
<span class="Keyword">def</span> <span class="Entity">macro_value_for</span>(<span class="Variable">macro_name</span>)
<span class="Keyword">if</span> macro_name.<span class="Entity">nil?</span> <span class="Keyword">or</span> macro_name<span class="Keyword">==</span><span class="String"><span class="String">&quot;</span><span class="String">&quot;</span></span> <span class="Keyword">or</span> <span class="Variable"><span class="Variable">@</span>macro</span>[macro_name.<span class="Entity">intern</span>].<span class="Entity">nil?</span>
<span class="Keyword">return</span> <span class="String"><span class="String">%{</span>%<span class="StringEmbeddedSource"><span class="StringEmbeddedSource">#{</span>macro_name<span class="StringEmbeddedSource">}</span></span><span class="String">}</span></span>
<span class="Keyword">end</span>
<span class="Keyword">return</span> <span class="Variable"><span class="Variable">@</span>macro</span>[macro_name.<span class="Entity">intern</span>]
<span class="Keyword">end</span>
<span class="Keyword">def</span> <span class="Entity">run</span>(<span class="Variable">content<span class="Variable">,</span> params<span class="Keyword">=</span><span class="Variable">{</span><span class="Variable">}</span></span>)
content.<span class="Entity">gsub</span>(<span class="StringRegexp"><span class="StringRegexp">/</span></span><span class="StringRegexp">%<span class="StringRegexp"><span class="StringRegexp">(</span><span class="StringRegexpSpecial">\w</span>*<span class="StringRegexp">)</span></span></span><span class="StringRegexp"><span class="StringRegexp">/</span></span>) <span class="Keyword">do </span>|<span class="Variable">m</span>|
<span class="Keyword">if</span> m <span class="Keyword">!=</span> <span class="String"><span class="String">'</span>%<span class="String">'</span></span>
<span class="Entity">macro_value_for</span>(<span class="Variable"><span class="Variable">$</span>1</span>)
<span class="Keyword">else</span>
m
<span class="Keyword">end</span>
<span class="Keyword">end</span>
<span class="Keyword">end</span>
<span class="Keyword">end</span>
</pre>
</div></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="choixrss">
<a id="rss" href="http://feeds.feedburner.com/yannespositocomfr">
s'abonner
</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#comment').hide();
$('#clickcomment').click(showComments);
});
function showComments() {
$('#comment').show();
$('#clickcomment').fadeOut();
}
document.write('<div id="clickcomment">Commentaires</div>');
</script>
<div class="flush"></div>
<div class="corps" id="comment">
<h2 class="first">commentaires</h2>
<noscript>
Vous devez activer javascript pour commenter.
</noscript>
<script type="text/javascript">
var idcomments_acct = 'a307f0044511ff1b5cfca573fc0a52e7';
var idcomments_post_id = '/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/';
var idcomments_post_url = 'http://yannesposito.com/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/';
2011-04-20 12:29:01 +00:00
</script>
<span id="IDCommentsPostTitle" style="display:none"></span>
<script type='text/javascript' src='/Scratch/js/genericCommentWrapperV2.js'></script>
2011-04-20 12:29:01 +00:00
</div>
<div id="entete" class="corps_spaced">
<div id="liens">
<ul><li><a href="/Scratch/fr/">Bienvenue</a></li>
<li><a href="/Scratch/fr/blog/">Blog</a></li>
<li><a href="/Scratch/fr/softwares/">Softwares</a></li>
<li><a href="/Scratch/fr/about/">À propos</a></li></ul>
2011-04-20 12:29:01 +00:00
</div>
<div class="flush"></div>
<hr/>
<div id="next_before_articles">
<div id="previous_articles">
articles précédents
<div class="previous_article">
<a href="/Scratch/fr/blog/2010-10-14-Fun-with-wav/"><span class="nicer">«</span>&nbsp;S'amuser avec un .wav</a>
2011-04-20 12:29:01 +00:00
</div>
<div class="previous_article">
<a href="/Scratch/fr/blog/2010-10-10-Secure-eMail-on-Mac-in-few-steps/"><span class="nicer">«</span>&nbsp;Sécurisez vos emails</a>
2011-04-20 12:29:01 +00:00
</div>
<div class="previous_article">
<a href="/Scratch/fr/blog/2010-10-06-New-Blog-Design-Constraints/"><span class="nicer">«</span>&nbsp;Contraintes du design de ce blog</a>
2011-04-20 12:29:01 +00:00
</div>
</div>
<div id="next_articles">
articles suivants
<div class="next_article">
<a href="/Scratch/fr/blog/2011-01-03-Happy-New-Year/">Bonne et heureuse année&nbsp;<span class="nicer">»</span></a>
2011-04-20 12:29:01 +00:00
</div>
<div class="next_article">
<a href="/Scratch/fr/blog/2011-01-03-Why-I-sadly-won-t-use-coffeescript/">Pourquoi je n'utiliserai pas CoffeeScript (malheureusement)&nbsp;<span class="nicer">»</span></a>
2011-04-20 12:29:01 +00:00
</div>
<div class="next_article">
2011-04-20 15:31:37 +00:00
<a href="/Scratch/fr/blog/2011-04-20-Now-hosted-on-github/">Hébergement github&nbsp;<span class="nicer">»</span></a>
</div>
2011-04-20 12:29:01 +00:00
</div>
<div class="flush"></div>
</div>
</div>
<div id="bottom">
<div>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.fr">Droits de reproduction ©, Yann Esposito</a>
</div>
<div id="lastmod">
Écrit le : 26/10/2010
2011-11-16 12:14:39 +00:00
modifié le : 26/10/2011
2011-04-20 12:29:01 +00:00
</div>
<div>
Site entièrement réalisé avec
<a href="http://www.vim.org">Vim</a>
et
<a href="http://nanoc.stoneship.org">nanoc</a>
</div>
<div>
<a href="/Scratch/fr/validation/">Validation</a>
2011-04-20 12:29:01 +00:00
<a href="http://validator.w3.org/check?uri=referer"> [xhtml] </a>
.
<a href="http://jigsaw.w3.org/css-validator/check/referer?profile=css3"> [css] </a>
.
<a href="http://validator.w3.org/feed/check.cgi?url=http%3A//yannesposito.com/Scratch/fr/blog/feed/feed.xml">[rss]</a>
2011-04-20 12:29:01 +00:00
</div>
</div>
<div class="clear"></div>
</div>
</body>
</html>