2021-04-18 10:23:24 +00:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< title > YBlog - LaTeX like macro for markdown< / title >
< meta name = "keywords" content = "LaTeX, macros, markdown, nanoc, ruby" / >
< link rel = "shortcut icon" type = "image/x-icon" href = "../../../../Scratch/img/favicon.ico" / >
2021-05-25 20:25:47 +00:00
< 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" / >
2021-04-18 10:23:24 +00:00
< 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 = "en" class = "article" >
< div id = "content" >
< div id = "header" >
< div id = "choix" >
< span id = "choixlang" >
< a href = "../../../../Scratch/fr/blog/2010-10-26-LaTeX-like-macro-and-markdown/" > French< / a >
< / span >
< span class = "tomenu" > < a href = "#navigation" > ↓ Menu ↓< / a > < / span >
< span class = "flush" > < / span >
< / div >
< / div >
< div id = "titre" >
< h1 > LaTeX like macro for markdown< / h1 >
< / div >
< div class = "flush" > < / div >
< div id = "afterheader" class = "article" >
< div class = "corps" >
< div class = "intro" >
< p > < span class = "sc" > < abbr title = "Too long; didn't read" > tl;dr< / abbr > : < / span > I made a simple macro system for my blog. Now I juste have to write %< span > < / span > latex and it show as < 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 > I added a macro system for my blog system. When we are used to < 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 > this lack can be hard to handle. Particularly when using mathematical notations. In the header of my files I simply write:< / p >
< div class = "sourceCode" id = "cb1" > < pre class = "sourceCode yaml" > < code class = "sourceCode yaml" > < / code > < / pre > < / div >
< p > In the body it will replace every occurrence of:< / p >
< ul >
< li > %< span > < / span > test by < em > Just a test< / em > ,< / li >
< li > and %< span > < / span > latex by < 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 > The source code is really simple. For < code > nanoc< / code > user, simply put this file in your < code > lib< / code > directory.< / 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: " passed test" < / 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 > < < 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" > < span class=" sc" > < abbr title=" Trop long à lire" > tlàl< /abbr> : < /span> < / 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" > < span class=" sc" > < abbr title=" Too long; didn't read" > tl;dr< /abbr> : < /span> < / 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" > " " < / 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 > Macros could be very useful, read < a href = "http://adam.gomaa.us/blog/2007/oct/22/markdown-doesnt-scale/index.html" > this article< / a > for example.< / p >
< / div >
< div id = "afterarticle" >
< div id = "social" >
2021-05-25 20:25:47 +00:00
< a href = "/rss.xml" target = "_blank" rel = "noopener noreferrer nofollow" class = "social" > RSS< / a >
2021-04-18 10:23:24 +00:00
·
< a href = "https://twitter.com/home?status=http%3A%2F%2Fyannesposito.com/Scratch/en/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/en/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/en/blog/Social-link-the-right-way/" > These social sharing links preserve your privacy< / a >
< / div >
< div id = "navigation" >
< a href = "../../../../" > Home< / a >
< span class = "sep" > ¦< / span >
< a href = "../../../../Scratch/en/blog" > Blog< / a >
< span class = "sep" > ¦< / span >
< a href = "../../../../Scratch/en/softwares" > Softwares< / a >
< span class = "sep" > ¦< / span >
< a href = "../../../../Scratch/en/about" > About< / 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" > & < / 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 >
< hr / >
< div style = "max-width: 100%" >
< a href = "https://cardanohub.org" >
< img src = "../../../../Scratch/img/ada-logo.png" class = "simple" style = "height: 16px ;
border-radius: 50%;
vertical-align:middle;
display:inline-block;" />
ADA:
< / a >
< code style = "display:inline-block;
word-wrap:break-word;
text-align: left;
vertical-align: top;
max-width: 85%;">
DdzFFzCqrhtAvdkmATx5Fm8NPJViDy85ZBw13p4XcNzVzvQg8e3vWLXq23JQWFxPEXK6Kvhaxxe7oJt4VMYHxpA2vtCFiP8fziohN6Yp
< / code >
< / div >
< / div >
< / div >
< / div >
< / div >
< / body >
< / html >