<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Le mpg-blog &#187; astuce</title>
	<atom:link href="http://weblog.elzevir.fr/par-tag/astuce/feed/" rel="self" type="application/rss+xml" />
	<link>http://weblog.elzevir.fr</link>
	<description>LaTeX et autres geekeries</description>
	<lastBuildDate>Fri, 10 Sep 2010 08:49:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Detexify</title>
		<link>http://weblog.elzevir.fr/2009/10/detexify/</link>
		<comments>http://weblog.elzevir.fr/2009/10/detexify/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 00:35:44 +0000</pubDate>
		<dc:creator>mpg</dc:creator>
				<category><![CDATA[TeX et compagnie]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[latex]]></category>

		<guid isPermaLink="false">http://weblog.elzevir.fr/2009/10/detexify/</guid>
		<description><![CDATA[Pour fêter la rentrée après des mois de silence, un tout petit billet en forme
de lien vers un outil génial, que j&#8217;ai découvert cet été, et dont j&#8217;ai réalisé
aujourd&#8217;hui que je n&#8217;en avais pas encore parlé à tous mes amis (on va voir si
mes amis lisent ce blog) : detexify.

C&#8217;est un outil en ligne qui permet [...]]]></description>
			<content:encoded><![CDATA[<p>Pour fêter la rentrée après des mois de silence, un tout petit billet en forme
de lien vers un outil génial, que j&#8217;ai découvert cet été, et dont j&#8217;ai réalisé
aujourd&#8217;hui que je n&#8217;en avais pas encore parlé à tous mes amis (on va voir si
mes amis lisent ce blog) : <a href="http://detexify.kirelabs.org/classify.html">detexify</a>.</p>

<p>C&#8217;est un outil en ligne qui permet de dessiner un symbole quelconque, en général
un symbole mathématique, et d&#8217;avoir en retour la commande LaTeX (avec le nom du
<em>package</em> qui la fournit, le cas échéant). C&#8217;est une façon efficace et,
avouons-le, bien marrante, de fouiller dans <a href="http://mirror.ctan.org/info/symbols/comprehensive/symbols-a4.pdf">symbols-a4</a>. Le seul avantage qui
reste à ce document, est qu&#8217;on peut le consulter hors-ligne facilement (avec les
commandes <code>texdoc symbols-a4</code> sous <a href="http://tug.org/texlive/">TeX Live</a> et <code>mthelp symbols-a4</code> sous
<a href="http://miktex.org/">MiKTeX</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://weblog.elzevir.fr/2009/10/detexify/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tester si une commande est définie en (La)TeX</title>
		<link>http://weblog.elzevir.fr/2008/07/tester-si-une-commande-est-definie-en-latex/</link>
		<comments>http://weblog.elzevir.fr/2008/07/tester-si-une-commande-est-definie-en-latex/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 16:47:58 +0000</pubDate>
		<dc:creator>mpg</dc:creator>
				<category><![CDATA[TeX et compagnie]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[latex]]></category>

		<guid isPermaLink="false">http://weblog.elzevir.fr/2008/07/9/</guid>
		<description><![CDATA[Reprise d&#8217;un de mes articles récents sur fctt, qui fait le point sur les
mille-et-une (en fait, un peu moins) façons de savoir si une séquence de
contrôle est définie ou non : en TeX pur, en LaTeX, en e-TeX, en distinguant ou
pas \relax de undefined&#8230;



Pour commencer, précisons que « non défini » et \relax
c&#8217;est pas pareil en [...]]]></description>
			<content:encoded><![CDATA[<p>Reprise d&#8217;un de mes articles récents sur fctt, qui fait le point sur les
mille-et-une (en fait, un peu moins) façons de savoir si une séquence de
contrôle est définie ou non : en TeX pur, en LaTeX, en e-TeX, en distinguant ou
pas <code>\relax</code> de <code>undefined</code>&#8230;</p>

<p><span id="more-9"></span></p>

<p>Pour commencer, précisons que « non défini » et <code>\relax</code>
c&#8217;est pas pareil en général :</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;">This is TeX, Version 3.1415926 (Web2C 7.5.7)
**<span style="color: #800000; font-weight: normal;">\show</span><span style="color: #800000; font-weight: normal;">\relax</span>
&gt; <span style="color: #800000; font-weight: normal;">\relax</span>=<span style="color: #800000; font-weight: normal;">\relax</span>.
&lt;*&gt; <span style="color: #800000; font-weight: normal;">\show</span><span style="color: #800000; font-weight: normal;">\relax</span>
&nbsp;
? 
&nbsp;
*<span style="color: #800000; font-weight: normal;">\show</span><span style="color: #800000; font-weight: normal;">\cettecommandenexistepas</span>
&gt; <span style="color: #800000; font-weight: normal;">\cettecommandenexistepas</span>=undefined.
&lt;*&gt; <span style="color: #800000; font-weight: normal;">\show</span><span style="color: #800000; font-weight: normal;">\cettecommandenexistepas</span>
&nbsp;
? x
No pages of output.
Transcript written on texput.log.</pre></div></div>


<p><code>\ifx</code> compare toujours les significations (« meaning ») des trucs : deux
trucs sont <code>\ifx</code>-égaux si et seulement si il ont la même signification. La
signification est à peu près ce qui est affiché par <code>\show</code>, sauf qu&#8217;avec
<code>\show</code> on perd les catcodes alors que bien sûr en vrai ils comptent.</p>

<p>Deuxième point : quand on forme avec <code>\csname</code> une séquence de contrôle dont
la signification était précedemment <code>undefined</code>, la séquence est
immédiatement rendue <code>\let</code>-égale à <code>\relax</code>. La porté de cette opération est
limité comme celle de toute assignation. Exemple :</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #800000; font-weight: normal;">\begingroup</span>
<span style="color: #800000; font-weight: normal;">\show</span><span style="color: #800000; font-weight: normal;">\undefined</span>     <span style="color: #2C922C; font-style: italic;">% \undefined=undefined</span>
<span style="color: #800000; font-weight: normal;">\csname</span> undefined<span style="color: #800000; font-weight: normal;">\endcsname</span>
<span style="color: #800000; font-weight: normal;">\show</span><span style="color: #800000; font-weight: normal;">\undefined</span>     <span style="color: #2C922C; font-style: italic;">% \undefined=\relax</span>
<span style="color: #800000; font-weight: normal;">\endgroup</span>
<span style="color: #800000; font-weight: normal;">\show</span><span style="color: #800000; font-weight: normal;">\undefined</span>     <span style="color: #2C922C; font-style: italic;">% \undefined=undefined</span></pre></div></div>


<p>Application, extraite de latex.ltx (ou de source2e) :</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">def</span></span><span style="color: #E00000; font-weight: normal;">\@ifundefined</span>#1<span style="color: #E02020; ">{</span><span style="color: #2C922C; font-style: italic;">%</span>
  <span style="color: #800000; font-weight: normal;">\expandafter</span><span style="color: #800000; font-weight: normal;">\ifx</span><span style="color: #800000; font-weight: normal;">\csname</span>#1<span style="color: #800000; font-weight: normal;">\endcsname</span><span style="color: #800000; font-weight: normal;">\relax</span>
    <span style="color: #800000; font-weight: normal;">\expandafter</span><span style="color: #E00000; font-weight: normal;">\@firstoftwo</span>
  <span style="color: #800000; font-weight: normal;">\else</span>
    <span style="color: #800000; font-weight: normal;">\expandafter</span><span style="color: #E00000; font-weight: normal;">\@secondoftwo</span>
  <span style="color: #800000; font-weight: normal;">\fi</span><span style="color: #E02020; ">}</span></pre></div></div>


<p>Usage :</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #E00000; font-weight: normal;">\@ifundefined</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">newcommand</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">Pas LaTeX</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">LaTeX</span><span style="color: #E02020; ">}</span></pre></div></div>


<p>Particularité : <code>\@ifundefined{relax}{Non}{Oui}</code> répond non. En LaTeX, on met
donc dans le même sac <code>\relax</code> et <code>undefined</code>, mais c&#8217;est un choix propre à
LaTeX. (Autre) inconvénient : dans le cas où on exécute la ligne ci-dessus
en Plain, c&#8217;est comme si on avait aussi fait <code>\let\newcommand\relax</code>.</p>

<p>Autres tests qui ne présentent pas ces inconvénients :</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #800000; font-weight: normal;">\ifx</span><span style="color: #800000; font-weight: normal;">\truc</span><span style="color: #800000; font-weight: normal;">\undefined</span> <span style="color: #2C922C; font-style: italic;">% par convention, on suppose que \undefined est non</span>
<span style="color: #2C922C; font-style: italic;">% définie, mais rien ne le garantit (on utilise aussi \@undefined)</span>
&nbsp;
<span style="color: #800000; font-weight: normal;">\ifx</span><span style="color: #800000; font-weight: normal;">\truc</span><span style="color: #800000; font-weight: normal;">\undefined</span>
  non def
<span style="color: #800000; font-weight: normal;">\else</span>
  <span style="color: #800000; font-weight: normal;">\ifx</span><span style="color: #800000; font-weight: normal;">\truc</span><span style="color: #800000; font-weight: normal;">\relax</span>
    non def <span style="color: #2C922C; font-style: italic;">% au sens de LaTeX</span>
  <span style="color: #800000; font-weight: normal;">\else</span>  
    def
  <span style="color: #800000; font-weight: normal;">\fi</span>
<span style="color: #800000; font-weight: normal;">\fi</span></pre></div></div>


<p>Le deuxième est vachement préférable dans un milieu plus ou moins LaTeXien,
car il y a vraiment un risque que quelqu&#8217;un ait fait un <code>\@ifundefined</code>
avant&#8230; Ces deux tests ne marchent que si on peut écrire la séquence de
contrôle sans problème (pas de caractères zarbis dans le nom). Sinon, on
peut utiliser :</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #800000; font-weight: normal;">\begingroup</span><span style="color: #800000; font-weight: normal;">\expandafter</span><span style="color: #800000; font-weight: normal;">\expandafter</span><span style="color: #800000; font-weight: normal;">\expandafter</span><span style="color: #800000; font-weight: normal;">\endgroup</span>
<span style="color: #800000; font-weight: normal;">\expandfater</span><span style="color: #800000; font-weight: normal;">\ifx</span><span style="color: #800000; font-weight: normal;">\csname</span> nom+bien/chelou<span style="color: #800000; font-weight: normal;">\endcsname</span><span style="color: #800000; font-weight: normal;">\relax</span></pre></div></div>


<p>qui a l&#8217;avantage de ne pas faire passer à <code>\relax</code> un truc qui était
undefined, mais l&#8217;inconvénient de ne plus être développable. En TeX
Knuthien, on ne peut pas faire mieux. En e-TeX, si.</p>

<p>On a d&#8217;abord <code>\ifdefined\truc</code> qui est l&#8217;exact équivalent de
<code>\ifx\truc\undefined</code> <em>sauf</em> qu&#8217;on a plus besoin de supposer que <code>\undefined</code>
est vraiment non définie. Ensuite, on a <code>\ifcsname truc+che/lou\endcsname</code>
qui fonctionne pareil et ne présente pas l&#8217;inconvénient de rendre <code>\truc</code>
égal à <code>\relax</code> s&#8217;il était précédemment non défini. Bref, le pied. (Le tout
était bien sûr développable, cela va sans dire.)</p>

<p>Comme souvent, la solution e-TeX est la meilleure techniquement, mais elle
n&#8217;etre pas très vite dans les mœurs, en particulier elle n&#8217;entrera pas dans le
noyau LaTeX avant la sortie de LaTeX3 (c&#8217;est-à-dire pas tout de suite). Pour une
interface LaTeXienne aux fonctionnalités d&#8217;e-TeX (et bien d&#8217;autres choses), je
recommande le paquet <a href="http://ctan.org/pkg/etoolbox">etoolbox</a>. Voir par exemple la section 3.5.1 de son
manuel, concernant des points discutés ici.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblog.elzevir.fr/2008/07/tester-si-une-commande-est-definie-en-latex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
