271 lines
No EOL
17 KiB
HTML
271 lines
No EOL
17 KiB
HTML
<?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" />
|
|
|
|
|
|
<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" />
|
|
<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>
|
|
<!--[if lt IE 9]>
|
|
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
|
|
<![endif]-->
|
|
<!-- < % if containMaths %>
|
|
<script type="text/javascript" src="/Scratch/js/MathJax/MathJax.js"></script>
|
|
< % end %>
|
|
-->
|
|
<title>Des macros LaTeX pour markdown</title>
|
|
</head>
|
|
<body lang="fr">
|
|
<script type="text/javascript">// <![CDATA[
|
|
document.write('<div id="blackpage"><img src="/Scratch/img/loading.gif" alt="Chargement en cours..."/></div>');
|
|
// ]]>
|
|
</script>
|
|
|
|
<div id="content">
|
|
|
|
<div id="choix">
|
|
<div class="return"><a href="#entete">↓ Menu ↓</a></div>
|
|
<div id="choixlang">
|
|
<a href="/Scratch/en/blog/2010-10-26-LaTeX-like-macro-and-markdown/" onclick="setLanguage('en')">in English</a>
|
|
</div>
|
|
</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">
|
|
|
|
|
|
<p><span class="sc"><abbr title="Trop long à lire">tlàl</abbr> : </span> J’ai fait un système simple de macros pour mon blog. Par exemple, il me suffit d’écrire %<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>J’ai ajouter un système de macro pour mon système de blog.
|
|
Lorsqu’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’on commence à écrire des articles
|
|
un peu conséquent avec des notations mathématiques,
|
|
les macros deviennent vite quelque chose d’indispensable.</p>
|
|
|
|
<p>Dans l’entête de mes fichiers j’écris simplement:</p>
|
|
|
|
<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">"</span>This is a macro test<span class="String">"</span></span>
|
|
<span class="MetaTagAll"><span class="MetaTagInline">latex</span><span class="MetaTagAll">:</span> </span><span class="String"><span class="String">'</span><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><span class="String">'</span></span>
|
|
</pre>
|
|
|
|
<p>Puis dans le corps ça va remplacer :</p>
|
|
|
|
<ul>
|
|
<li>%<span />test par <em>This is a macro test</em> ;</li>
|
|
<li>et %<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="code"><div class="file"><a href="/Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/code/macros.rb"> ➥ macros.rb </a></div><div class="withfile">
|
|
<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: "passed test"</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"><</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>{}
|
|
<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><span class="sc"><abbr title="Trop long à lire">tlàl</abbr> : </span><span class="String">}</span></span>
|
|
<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><span class="sc"><abbr title="Too long; didn't read">tl;dr</abbr>: </span><span class="String">}</span></span>
|
|
<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">"</span><span class="String">"</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/';
|
|
</script>
|
|
<span id="IDCommentsPostTitle" style="display:none"></span>
|
|
<script type='text/javascript' src='/Scratch/js/genericCommentWrapperV2.js'></script>
|
|
|
|
</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>
|
|
</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> S'amuser avec un .wav</a>
|
|
</div>
|
|
|
|
|
|
<div class="previous_article">
|
|
<a href="/Scratch/fr/blog/2010-10-10-Secure-eMail-on-Mac-in-few-steps/"><span class="nicer">«</span> Sécurisez vos emails</a>
|
|
</div>
|
|
|
|
|
|
<div class="previous_article">
|
|
<a href="/Scratch/fr/blog/2010-10-06-New-Blog-Design-Constraints/"><span class="nicer">«</span> Contraintes du design de ce blog</a>
|
|
</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 <span class="nicer">»</span></a>
|
|
</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) <span class="nicer">»</span></a>
|
|
</div>
|
|
|
|
|
|
<div class="next_article">
|
|
<a href="/Scratch/fr/blog/2011-04-20-Now-hosted-on-github/">Hébergement github <span class="nicer">»</span></a>
|
|
</div>
|
|
|
|
|
|
</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
|
|
modifié le : 02/09/2011
|
|
</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>
|
|
<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>
|
|
</div>
|
|
</div>
|
|
<div class="clear"></div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
var clicky = { log: function(){ return; }, goal: function(){ return; }};
|
|
var clicky_site_id = 66374971;
|
|
(function() {
|
|
var s = document.createElement('script');
|
|
s.type = 'text/javascript';
|
|
s.async = true;
|
|
s.src = ( document.location.protocol == 'https:' ? 'https://static.getclicky.com/js' : 'http://static.getclicky.com/js' );
|
|
( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
|
|
})();
|
|
</script>
|
|
<noscript><p><img alt="Clicky" width="1" height="1" src="http://in.getclicky.com/66374971ns.gif" /></p></noscript>
|
|
|
|
</body>
|
|
</html> |