{"id":679,"date":"2018-09-11T19:01:41","date_gmt":"2018-09-11T17:01:41","guid":{"rendered":"https:\/\/www.mathweb.fr\/euclide\/?p=679"},"modified":"2020-10-02T18:17:04","modified_gmt":"2020-10-02T16:17:04","slug":"generer-une-feuille-dexercices-aleatoires-avec-python-en-latex","status":"publish","type":"post","link":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/","title":{"rendered":"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">G\u00e9n\u00e9rer une feuille d&rsquo;exercices al\u00e9atoires avec Python en LaTeX : combien de fois ai-je voulu g\u00e9n\u00e9rer automatiquement des exercices similaires (par exemple, de d\u00e9veloppement) ? Vous ne le savez pas, mais moi, je le sais : beaucoup trop !<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Encore aujourd&rsquo;hui, j&rsquo;ai voulu g\u00e9n\u00e9rer une s\u00e9rie de multiplications pour faire r\u00e9viser ses tables une de mes \u00e9l\u00e8ves.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Comme je me suis mis \u00e0 Python il n&rsquo;y a pas longtemps, et comme dans la foul\u00e9e je me suis aussi mis \u00e0 <a href=\"https:\/\/ctan.org\/pkg\/pythontex\" target=\"_blank\" rel=\"noreferrer noopener\">PythonTeX<\/a>, j&rsquo;ai forc\u00e9ment pens\u00e9 \u00e0 tout \u00e7a pour faire ma feuille d&rsquo;exercices (plut\u00f4t que d&rsquo;inventer et de taper plus de 90 op\u00e9rations).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nous allons voir comment.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-white ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Au menu sur cette page...<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#Generer_des_exercices_aleatoires_en_LaTeX_du_cote_de_Python\" >G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: du c\u00f4t\u00e9 de Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#Generer_des_exercices_aleatoires_en_LaTeX_du_cote_de_LaTeX\" >G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: du c\u00f4t\u00e9 de \\(\\LaTeX\\)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#Generer_des_exercices_aleatoires_en_LaTeX_allons_plus_loin_avec_de_lalgebre\" >G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: allons plus loin avec de l&rsquo;alg\u00e8bre<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#Generer_des_exercices_aleatoires_en_LaTeX_installation_de_sympy\" >G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: installation de sympy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#Le_code_Python\" >Le code Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#Le_code_LaTeX\" >Le code&nbsp;\\(\\LaTeX\\)<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Generer_des_exercices_aleatoires_en_LaTeX_du_cote_de_Python\"><\/span>G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: du c\u00f4t\u00e9 de Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dans un premier temps, il faut un code Python qui fonctionne. Je lance donc IDLE (la console Python) et tape le code suivant :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import random\n\nfor n in range(10):\n    a = random.randint(2,9)\n    b = random.randint(2,9)\n    c = a*b\n    if (n%3 == 0):\n        print('... x ',b,' = ',c)\n    else:\n        if (n%3 == 1):\n            print(a,' x ... = ',c)\n        else:\n            print(a,' x ',b,' = ...')<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ce code me sert juste \u00e0 valider la syntaxe : tout va bien ! Cela me sort 10 op\u00e9rations \u00e0 trous comme l&rsquo;illustre la copie d&rsquo;\u00e9cran suivante :<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"129\" height=\"163\" src=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/operations-a-trou.png\" alt=\"g\u00e9n\u00e9rer exercices al\u00e9atoires latex python\" class=\"wp-image-680\"\/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Maintenant, il faut que je passe aux choses s\u00e9rieuse : cr\u00e9er la feuille d&rsquo;exercices \\(\\LaTeX\\).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Generer_des_exercices_aleatoires_en_LaTeX_du_cote_de_LaTeX\"><\/span>G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: du c\u00f4t\u00e9 de \\(\\LaTeX\\)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">J&rsquo;utilise le code suivant :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\documentclass[12pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[french]{babel}\n\\usepackage[T1]{fontenc}\n\\usepackage{lmodern}\n\\usepackage{amsmath}\n\\usepackage{multicol}\n\\usepackage{pythontex}\n\\usepackage{nopageno}\n\\setlength{\\parindent}{0pt}\n\\setlength{\\columnseprule}{0.4pt}\n\\begin{document}\n\\begin{multicols}{4}\n\\begin{pycode}\nimport random\nfor n in range(91):\n    a = random.randint(2,9)\n    b = random.randint(2,9)\n    c = a*b\n    if (n%3 == 0):\n        print('$\\\\ldots\\\\times',b,' = ',c,'$\\\\\\\\[1em]')\n    else:\n        if (n%3 == 1):\n            print('$',a,'\\\\times\\\\ldots = ',c,'$\\\\\\\\[1em]')\n        else:\n            print('$',a,'\\\\times',b,' = \\\\ldots$\\\\\\\\[1em]')\n\\end{pycode}\n\\end{multicols}\n\\end{documents}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Remarquez que j&rsquo;ai d\u00fb ajouter des symboles \u00ab\u00a0$\u00a0\u00bb (pour \u00e9crire les op\u00e9rations en mode math\u00e9matique en ligne) et que j&rsquo;ai d\u00fb doubler les antislashs (c&rsquo;est un probl\u00e8me r\u00e9current quand on passe par un programme externe, comme Xcas). J&rsquo;ai aussi remplac\u00e9 les \u00ab\u00a0x\u00a0\u00bb par des vraies crois Saint-Andr\u00e9 (\u00ab\u00a0\\times\u00a0\u00bb), \u00e7a fait plus pro !<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">L\u00e0, j&rsquo;obtiens la feuille suivante :<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a  href=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/Op\u00e9rations-al\u00e9atoires-pythontex.pdf\" data-fancybox data-type=\"iframe\" data-width=\"90%\" data-height=\"100%\" data-preload=\"false\">Op\u00e9rations al\u00e9atoires (pythontex)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Generer_des_exercices_aleatoires_en_LaTeX_allons_plus_loin_avec_de_lalgebre\"><\/span>G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: allons plus loin avec de l&rsquo;alg\u00e8bre<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Generer_des_exercices_aleatoires_en_LaTeX_installation_de_sympy\"><\/span>G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX: installation de sympy<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Pour faire de l&rsquo;alg\u00e8bre avec Python, on a besoin du module sympy. Il faut donc aller dans le terminal, et taper :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python -m pip install sympy<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Le_code_Python\"><\/span>Le code Python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Je souhaite un code qui choisisse al\u00e9atoirement 4 nombres entiers&nbsp;<em>a<\/em>,&nbsp;<em>b<\/em>,&nbsp;<em>c<\/em> et&nbsp;<em>d<\/em> et qui affiche l&rsquo;op\u00e9ration (<em>ax<\/em> +&nbsp;<em>b<\/em>)(<em>cx<\/em> +&nbsp;<em>d<\/em>) ainsi que son d\u00e9veloppement.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import random\nfrom sympy import Symbol\nfrom sympy import expand\nx=Symbol('x')\nfor n in range(11):\n    a = random.choice([1, -1]) * random.randint(2, 9)\n    b = random.choice([1, -1]) * random.randint(2, 9)\n    c = random.choice([1, -1]) * random.randint(2, 9)\n    d = random.choice([1, -1]) * random.randint(2, 9)\n    e = (a*x+b)*(c*x+d)       \n    print(expr,'=',expand(e))<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Le_code_LaTeX\"><\/span>Le code&nbsp;\\(\\LaTeX\\)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"latex\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\documentclass[12pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[french]{babel}\n\\usepackage[T1]{fontenc}\n\\usepackage{lmodern}\n\\usepackage{amsmath}\n\\usepackage{pythontex}\n\\usepackage{nopageno}\n\\usepackage{xstring}\n\\setlength{\\parindent}{0pt}\n\\begin{document}\n\\begin{pycode}\nimport random\nfrom sympy import Symbol\nfrom sympy import expand\nx=Symbol('x')\nprint('\\\\begin{align*}')\nfor n in range(10):\n    a = random.choice([1, -1]) * random.randint(2, 9)\n    b = random.choice([1, -1]) * random.randint(2, 9)\n    c = random.choice([1, -1]) * random.randint(2, 9)\n    d = random.choice([1, -1]) * random.randint(2, 9)\n    e = (a*x+b)*(c*x+d)       \n    print('\\\\StrSubstitute{',e,'}{*}{}',' &amp; = \\\\StrSubstitute{',expand(e),'}{**}{^}[\\\\result]\\\\StrSubstitute{\\\\result}{*}{}\\\\\\\\')\nprint('\\\\end{align*}')\n\\end{pycode}        \n\\end{document}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Cela donne :<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/developpements-python-alignement.png\" data-fancybox=\"gallery\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"234\" src=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/developpements-python-alignement-300x234.png\" alt=\"g\u00e9n\u00e9rer exercices al\u00e9atoires latex python\" class=\"wp-image-720\" srcset=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/developpements-python-alignement-300x234.png 300w, https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/developpements-python-alignement.png 497w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Pour passer du code Python au code \\(\\LaTeX\\), il m&rsquo;a fallu utiliser une petite astuce pour remplacer les \u00e9toiles (affich\u00e9es par Python). J&rsquo;ai donc fait appel au package <em>xstring<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Par d\u00e9faut, Python affiche : \u00ab\u00a0(-4*x+4)*(5*x+9)=-20*x**2-16*x+36\u00a0\u00bb; il faut donc :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>remplacer d&rsquo;abord les \u00ab\u00a0**\u00a0\u00bb par des \u00ab\u00a0^\u00a0\u00bb, d&rsquo;o\u00f9 la commande : \\StrSubstitute{&lt;ma cha\u00eene&gt;}{**}{^}[\\result]. Cette commande d\u00e9finit la macro \\result comme \u00e9tant la cha\u00eene dans laquelle on a fait le remplacement.<\/li><li>remplacer les \u00ab\u00a0*\u00a0\u00bb par rien dans \\result : \\StrSubstitute{\\result}{*}{}. On obtient alors le r\u00e9sultat final souhait\u00e9.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Remarquez que j&rsquo;ai d\u00fb ajouter des symboles \u00ab\u00a0$\u00a0\u00bb (pour \u00e9crire les op\u00e9rations en mode math\u00e9matique en ligne) et que j&rsquo;ai d\u00fb doubler les antislashs (c&rsquo;est un probl\u00e8me r\u00e9current quand on passe par un programme externe, comme Xcas). J&rsquo;ai aussi remplac\u00e9 les \u00ab\u00a0x\u00a0\u00bb par des vraies crois Saint-Andr\u00e9 (\u00ab\u00a0\\times\u00a0\u00bb), \u00e7a fait plus pro !<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">L\u00e0, j&rsquo;obtiens la feuille suivante :<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><a  href=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/Op\u00e9rations-al\u00e9atoires-pythontex.pdf\" data-fancybox data-type=\"iframe\" data-width=\"90%\" data-height=\"100%\" data-preload=\"false\">Op\u00e9rations al\u00e9atoires (pythontex)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>G\u00e9n\u00e9rer une feuille d&rsquo;exercices al\u00e9atoires avec Python en LaTeX : combien de fois ai-je voulu g\u00e9n\u00e9rer automatiquement des exercices similaires (par exemple, de d\u00e9veloppement) ? Vous ne le savez pas, mais moi, je le sais : beaucoup trop ! Encore aujourd&rsquo;hui, j&rsquo;ai voulu g\u00e9n\u00e9rer une s\u00e9rie de multiplications pour faire [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3691,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,1,5],"tags":[67,65,66],"class_list":["post-679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enseignement","category-latex","category-python","tag-aleatoire","tag-pythontex","tag-xstring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python<\/title>\n<meta name=\"description\" content=\"G\u00e9n\u00e9rer une feuille d&#039;exercices al\u00e9atoires sur un m\u00eame mod\u00e8le en LaTeX, c&#039;est possible avec l&#039;aide de Python. C&#039;est pratique pour une classe!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python\" \/>\n<meta property=\"og:description\" content=\"G\u00e9n\u00e9rer une feuille d&#039;exercices al\u00e9atoires sur un m\u00eame mod\u00e8le en LaTeX, c&#039;est possible avec l&#039;aide de Python. C&#039;est pratique pour une classe!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/\" \/>\n<meta property=\"og:site_name\" content=\"Mathweb.fr\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-11T17:01:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-02T16:17:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/feuille-exercices-aleatoires-python-latex.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"741\" \/>\n\t<meta property=\"og:image:height\" content=\"402\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"St\u00e9phane Pasquet\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"St\u00e9phane Pasquet\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/\"},\"author\":{\"name\":\"St\u00e9phane Pasquet\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#\\\/schema\\\/person\\\/e4d3bb07968238378f0d5052a70dcd69\"},\"headline\":\"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python\",\"datePublished\":\"2018-09-11T17:01:41+00:00\",\"dateModified\":\"2020-10-02T16:17:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/\"},\"wordCount\":565,\"commentCount\":15,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#\\\/schema\\\/person\\\/e4d3bb07968238378f0d5052a70dcd69\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/feuille-exercices-aleatoires-python-latex.jpg\",\"keywords\":[\"al\u00e9atoire\",\"pythontex\",\"xstring\"],\"articleSection\":[\"Enseignement\",\"LaTeX\",\"Python\"],\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/\",\"url\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/\",\"name\":\"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/feuille-exercices-aleatoires-python-latex.jpg\",\"datePublished\":\"2018-09-11T17:01:41+00:00\",\"dateModified\":\"2020-10-02T16:17:04+00:00\",\"description\":\"G\u00e9n\u00e9rer une feuille d'exercices al\u00e9atoires sur un m\u00eame mod\u00e8le en LaTeX, c'est possible avec l'aide de Python. C'est pratique pour une classe!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/feuille-exercices-aleatoires-python-latex.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2018\\\/09\\\/feuille-exercices-aleatoires-python-latex.jpg\",\"width\":741,\"height\":402,\"caption\":\"feuille exercices aleatoires python latex\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2018\\\/09\\\/11\\\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#website\",\"url\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/\",\"name\":\"Mathweb.fr\",\"description\":\"Math\u00e9matiques, LaTeX et Python\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#\\\/schema\\\/person\\\/e4d3bb07968238378f0d5052a70dcd69\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#\\\/schema\\\/person\\\/e4d3bb07968238378f0d5052a70dcd69\",\"name\":\"St\u00e9phane Pasquet\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/cropped-logo-mathweb.webp\",\"url\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/cropped-logo-mathweb.webp\",\"contentUrl\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/cropped-logo-mathweb.webp\",\"width\":74,\"height\":77,\"caption\":\"St\u00e9phane Pasquet\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/cropped-logo-mathweb.webp\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python","description":"G\u00e9n\u00e9rer une feuille d'exercices al\u00e9atoires sur un m\u00eame mod\u00e8le en LaTeX, c'est possible avec l'aide de Python. C'est pratique pour une classe!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/","og_locale":"fr_FR","og_type":"article","og_title":"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python","og_description":"G\u00e9n\u00e9rer une feuille d'exercices al\u00e9atoires sur un m\u00eame mod\u00e8le en LaTeX, c'est possible avec l'aide de Python. C'est pratique pour une classe!","og_url":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/","og_site_name":"Mathweb.fr","article_published_time":"2018-09-11T17:01:41+00:00","article_modified_time":"2020-10-02T16:17:04+00:00","og_image":[{"width":741,"height":402,"url":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/feuille-exercices-aleatoires-python-latex.jpg","type":"image\/jpeg"}],"author":"St\u00e9phane Pasquet","twitter_card":"summary_large_image","twitter_misc":{"\u00c9crit par":"St\u00e9phane Pasquet","Dur\u00e9e de lecture estim\u00e9e":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#article","isPartOf":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/"},"author":{"name":"St\u00e9phane Pasquet","@id":"https:\/\/www.mathweb.fr\/euclide\/#\/schema\/person\/e4d3bb07968238378f0d5052a70dcd69"},"headline":"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python","datePublished":"2018-09-11T17:01:41+00:00","dateModified":"2020-10-02T16:17:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/"},"wordCount":565,"commentCount":15,"publisher":{"@id":"https:\/\/www.mathweb.fr\/euclide\/#\/schema\/person\/e4d3bb07968238378f0d5052a70dcd69"},"image":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/feuille-exercices-aleatoires-python-latex.jpg","keywords":["al\u00e9atoire","pythontex","xstring"],"articleSection":["Enseignement","LaTeX","Python"],"inLanguage":"fr-FR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/","url":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/","name":"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python","isPartOf":{"@id":"https:\/\/www.mathweb.fr\/euclide\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#primaryimage"},"image":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/feuille-exercices-aleatoires-python-latex.jpg","datePublished":"2018-09-11T17:01:41+00:00","dateModified":"2020-10-02T16:17:04+00:00","description":"G\u00e9n\u00e9rer une feuille d'exercices al\u00e9atoires sur un m\u00eame mod\u00e8le en LaTeX, c'est possible avec l'aide de Python. C'est pratique pour une classe!","breadcrumb":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#primaryimage","url":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/feuille-exercices-aleatoires-python-latex.jpg","contentUrl":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2018\/09\/feuille-exercices-aleatoires-python-latex.jpg","width":741,"height":402,"caption":"feuille exercices aleatoires python latex"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/generer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.mathweb.fr\/euclide\/"},{"@type":"ListItem","position":2,"name":"G\u00e9n\u00e9rer des exercices al\u00e9atoires en LaTeX avec Python"}]},{"@type":"WebSite","@id":"https:\/\/www.mathweb.fr\/euclide\/#website","url":"https:\/\/www.mathweb.fr\/euclide\/","name":"Mathweb.fr","description":"Math\u00e9matiques, LaTeX et Python","publisher":{"@id":"https:\/\/www.mathweb.fr\/euclide\/#\/schema\/person\/e4d3bb07968238378f0d5052a70dcd69"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mathweb.fr\/euclide\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":["Person","Organization"],"@id":"https:\/\/www.mathweb.fr\/euclide\/#\/schema\/person\/e4d3bb07968238378f0d5052a70dcd69","name":"St\u00e9phane Pasquet","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2025\/06\/cropped-logo-mathweb.webp","url":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2025\/06\/cropped-logo-mathweb.webp","contentUrl":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2025\/06\/cropped-logo-mathweb.webp","width":74,"height":77,"caption":"St\u00e9phane Pasquet"},"logo":{"@id":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2025\/06\/cropped-logo-mathweb.webp"}}]}},"_links":{"self":[{"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":0,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/media\/3691"}],"wp:attachment":[{"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}