{"id":1157,"date":"2019-04-18T11:15:41","date_gmt":"2019-04-18T09:15:41","guid":{"rendered":"https:\/\/www.mathweb.fr\/euclide\/?p=1157"},"modified":"2024-06-09T17:06:36","modified_gmt":"2024-06-09T15:06:36","slug":"creer-un-fichier-latex-avec-python","status":"publish","type":"post","link":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/","title":{"rendered":"Cr\u00e9er un fichier LaTeX avec Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Cr\u00e9er un fichier LaTeX avec Python. Dans un <a href=\"https:\/\/www.mathweb.fr\/euclide\/2018\/09\/11\/engendrer-une-feuille-dexercices-aleatoires-avec-python-en-latex\/\">article pr\u00e9c\u00e9dent<\/a>, je vous expliquais comment, dans un fichier \\(\\LaTeX\\), on pouvait se servir de Python gr\u00e2ce \u00e0 l&#8217;extension <em>Pythontex<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Maintenant, je vais vous expliquer comment faire l&#8217;inverse, \u00e0 savoir comment cr\u00e9er et compiler un fichier \\(\\LaTeX\\) avec un programme Python.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">L&#8217;objectif va \u00eatre le m\u00eame que dans l&#8217;article pr\u00e9c\u00e9dent (cas d&#8217;\u00e9cole) : cr\u00e9er 20 d\u00e9veloppements (avec double distributivit\u00e9) al\u00e9atoires.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"360\" src=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/screenshot.gif\" alt=\"Cr\u00e9er un fichier LaTeX avec Python\" class=\"wp-image-1161\"\/><figcaption class=\"wp-element-caption\">Cr\u00e9er un fichier TeX et le compiler sous Python<\/figcaption><\/figure>\n<\/div>\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 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\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#Creer_un_fichier_LaTeX_avec_Python_importation_des_modules_necessaires\" >Cr\u00e9er un fichier LaTeX avec Python: importation des modules n\u00e9cessaires<\/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\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#Creer_un_fichier_LaTeX_avec_Python_construction_du_fichier\" >Cr\u00e9er un fichier LaTeX avec Python: construction du fichier<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#Creer_un_fichier_LaTeX_avec_Python_definir_le_preambule\" >Cr\u00e9er un fichier LaTeX avec Python: d\u00e9finir le pr\u00e9ambule<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#Generation_des_egalites\" >G\u00e9n\u00e9ration des \u00e9galit\u00e9s<\/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\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#Ecriture_du_fichier\" >\u00c9criture du fichier<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#Compilation\" >Compilation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#Le_code_complet\" >Le code complet<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creer_un_fichier_LaTeX_avec_Python_importation_des_modules_necessaires\"><\/span>Cr\u00e9er un fichier LaTeX avec Python: importation des modules n\u00e9cessaires<span class=\"ez-toc-section-end\"><\/span><\/h2>\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 os.path\nimport random\nfrom sympy import Symbol\nfrom sympy import expand\nx=Symbol('x')<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">J&#8217;importe le module <em>os<\/em> car il va me servir \u00e0 ex\u00e9cuter des commandes en lignes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ensuite, j&#8217;importe le module <em>random<\/em> car il est n\u00e9cessaire dans notre contexte (d\u00e8s lors qu&#8217;il y a choix al\u00e9atoire&#8230;).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">J&#8217;utilise ensuite <em>sympy<\/em> pour les manipulations alg\u00e9briques (c&#8217;est sp\u00e9cifique ici \u00e0 ce que je souhaite faire). Je d\u00e9finis alors &#8220;x&#8221; comme le symbole d\u00e9signant l&#8217;inconnue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creer_un_fichier_LaTeX_avec_Python_construction_du_fichier\"><\/span>Cr\u00e9er un fichier LaTeX avec Python: construction du fichier<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Le contenu du fichier va \u00eatre d\u00e9fini par une succession de texte.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creer_un_fichier_LaTeX_avec_Python_definir_le_preambule\"><\/span>Cr\u00e9er un fichier LaTeX avec Python: d\u00e9finir le pr\u00e9ambule<span class=\"ez-toc-section-end\"><\/span><\/h3>\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=\"\">def preambule(*packages):\n\tp = \"\"\n\tfor i in packages:\n\t\tp = p+\"\\\\usepackage{\"+i+\"}\\n\"\n\treturn p<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Cette fonction a pour but d&#8217;appeler tous les packages n\u00e9cessaires.<\/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=\"\">start = \"\\\\documentclass[12pt,a4paper,french]{article}\\n\\\\usepackage[utf8]{inputenc}\\n\"\nstart = start+preambule('amsmath','lmodern','babel')\nstart = start+\"\\\\begin{document}\\n\\\\begin{align*}\\n\"\n\nend = \"\\\\end{align*}\\n\\\\end{document}\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On commence par d\u00e9finir la classe utilis\u00e9e (avec les options souhait\u00e9es) ainsi que l&#8217;encodage. Puis, on appelle tous les packages souhait\u00e9s. Enfin, on commence le document.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Generation_des_egalites\"><\/span>G\u00e9n\u00e9ration des \u00e9galit\u00e9s<span class=\"ez-toc-section-end\"><\/span><\/h3>\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=\"\">body = \"\"\n\nfor n in range(21):\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    eresultchain = str(expand(e)) # on convertit le r\u00e9sultat en cha\u00eene de caract\u00e8res\n    eresultchain = eresultchain.replace('**','^') # on met au format TeX les exposants\n    eresultchain = eresultchain.replace('*','') # on \u00e9limine les symboles '*'\n    echain = str(e)\n    echain = echain.replace('*','')\n\n    body = body+echain+\" &amp; = \"+eresultchain+\"\\\\\\\\\\n\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Il est ici n\u00e9cessaire d&#8217;anticiper sur la syntaxe \\(\\LaTeX\\) pour remplacer certains caract\u00e8res&#8230;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Ecriture_du_fichier\"><\/span>\u00c9criture du fichier<span class=\"ez-toc-section-end\"><\/span><\/h3>\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=\"\">container = start+body+end\n\nfile = \"monfichier.tex\"\nif os.path.exists(file):\n\tos.remove(file)\n\nfichier = open(\"monfichier.tex\",\"x\") # \"x\" pour la cr\u00e9ation et l'\u00e9criture\nfichier.write(container)\nfichier.close()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Compilation\"><\/span>Compilation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Une fois le fichier cr\u00e9\u00e9, il est pratique de le compiler directement puis de l&#8217;afficher.<\/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=\"\">instructions = \"pdflatex \"+file#\"\nos.system(instructions)\n\nreadpdf = \"START \"+file[:-4]+\".pdf\"\nos.system(readpdf)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Et voil\u00e0 ! Une feuille d&#8217;exercices cr\u00e9\u00e9e en \u00e0 peine 2 secondes&#8230;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Le_code_complet\"><\/span>Le code complet<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Le code complet ci-dessous:<\/p>\n\n\n\n<div class=\"wp-block-file aligncenter\"><a href=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/Creer-fichier-tex.zip\">Creer fichier tex<\/a><a href=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/Creer-fichier-tex.zip\" class=\"wp-block-file__button wp-element-button\" download>T\u00e9l\u00e9charger<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Cr\u00e9er un fichier LaTeX avec Python. Dans un article pr\u00e9c\u00e9dent, je vous expliquais comment, dans un fichier \\(\\LaTeX\\), on pouvait se servir de Python gr\u00e2ce \u00e0 l&#8217;extension Pythontex. Maintenant, je vais vous expliquer comment faire l&#8217;inverse, \u00e0 savoir comment cr\u00e9er et compiler un fichier \\(\\LaTeX\\) avec un programme Python.<\/p>\n","protected":false},"author":1,"featured_media":1161,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1,6,5],"tags":[],"class_list":["post-1157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-informatique","category-latex","category-mathematiques","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Cr\u00e9er un fichier LaTeX avec Python - Mathweb.fr - Exemple de code<\/title>\n<meta name=\"description\" content=\"Nous allons voir dans cet article une fa\u00e7on de cr\u00e9er un fichier LaTeX (une fiche d&#039;exercices sur les d\u00e9veloppement) \u00e0 l&#039;aide de Python.\" \/>\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\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Cr\u00e9er un fichier LaTeX avec Python - Mathweb.fr - Exemple de code\" \/>\n<meta property=\"og:description\" content=\"Nous allons voir dans cet article une fa\u00e7on de cr\u00e9er un fichier LaTeX (une fiche d&#039;exercices sur les d\u00e9veloppement) \u00e0 l&#039;aide de Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Mathweb.fr\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-18T09:15:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-09T15:06:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/screenshot.gif\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/gif\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/\"},\"author\":{\"name\":\"St\u00e9phane Pasquet\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#\\\/schema\\\/person\\\/e4d3bb07968238378f0d5052a70dcd69\"},\"headline\":\"Cr\u00e9er un fichier LaTeX avec Python\",\"datePublished\":\"2019-04-18T09:15:41+00:00\",\"dateModified\":\"2024-06-09T15:06:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/\"},\"wordCount\":324,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#\\\/schema\\\/person\\\/e4d3bb07968238378f0d5052a70dcd69\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/screenshot.gif\",\"articleSection\":[\"Informatique\",\"LaTeX\",\"Math\u00e9matiques\",\"Python\"],\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/\",\"url\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/\",\"name\":\"Cr\u00e9er un fichier LaTeX avec Python - Mathweb.fr - Exemple de code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/screenshot.gif\",\"datePublished\":\"2019-04-18T09:15:41+00:00\",\"dateModified\":\"2024-06-09T15:06:36+00:00\",\"description\":\"Nous allons voir dans cet article une fa\u00e7on de cr\u00e9er un fichier LaTeX (une fiche d'exercices sur les d\u00e9veloppement) \u00e0 l'aide de Python.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/screenshot.gif\",\"contentUrl\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/screenshot.gif\",\"width\":640,\"height\":360,\"caption\":\"Cr\u00e9er un fichier TeX et le compiler sous Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/2019\\\/04\\\/18\\\/creer-un-fichier-latex-avec-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/www.mathweb.fr\\\/euclide\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Cr\u00e9er un fichier 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":"Cr\u00e9er un fichier LaTeX avec Python - Mathweb.fr - Exemple de code","description":"Nous allons voir dans cet article une fa\u00e7on de cr\u00e9er un fichier LaTeX (une fiche d'exercices sur les d\u00e9veloppement) \u00e0 l'aide de Python.","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\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/","og_locale":"fr_FR","og_type":"article","og_title":"Cr\u00e9er un fichier LaTeX avec Python - Mathweb.fr - Exemple de code","og_description":"Nous allons voir dans cet article une fa\u00e7on de cr\u00e9er un fichier LaTeX (une fiche d'exercices sur les d\u00e9veloppement) \u00e0 l'aide de Python.","og_url":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/","og_site_name":"Mathweb.fr","article_published_time":"2019-04-18T09:15:41+00:00","article_modified_time":"2024-06-09T15:06:36+00:00","og_image":[{"width":640,"height":360,"url":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/screenshot.gif","type":"image\/gif"}],"author":"St\u00e9phane Pasquet","twitter_card":"summary_large_image","twitter_misc":{"\u00c9crit par":"St\u00e9phane Pasquet","Dur\u00e9e de lecture estim\u00e9e":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#article","isPartOf":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/"},"author":{"name":"St\u00e9phane Pasquet","@id":"https:\/\/www.mathweb.fr\/euclide\/#\/schema\/person\/e4d3bb07968238378f0d5052a70dcd69"},"headline":"Cr\u00e9er un fichier LaTeX avec Python","datePublished":"2019-04-18T09:15:41+00:00","dateModified":"2024-06-09T15:06:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/"},"wordCount":324,"commentCount":3,"publisher":{"@id":"https:\/\/www.mathweb.fr\/euclide\/#\/schema\/person\/e4d3bb07968238378f0d5052a70dcd69"},"image":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/screenshot.gif","articleSection":["Informatique","LaTeX","Math\u00e9matiques","Python"],"inLanguage":"fr-FR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/","url":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/","name":"Cr\u00e9er un fichier LaTeX avec Python - Mathweb.fr - Exemple de code","isPartOf":{"@id":"https:\/\/www.mathweb.fr\/euclide\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#primaryimage"},"image":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/screenshot.gif","datePublished":"2019-04-18T09:15:41+00:00","dateModified":"2024-06-09T15:06:36+00:00","description":"Nous allons voir dans cet article une fa\u00e7on de cr\u00e9er un fichier LaTeX (une fiche d'exercices sur les d\u00e9veloppement) \u00e0 l'aide de Python.","breadcrumb":{"@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#primaryimage","url":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/screenshot.gif","contentUrl":"https:\/\/www.mathweb.fr\/euclide\/wp-content\/uploads\/2019\/04\/screenshot.gif","width":640,"height":360,"caption":"Cr\u00e9er un fichier TeX et le compiler sous Python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mathweb.fr\/euclide\/2019\/04\/18\/creer-un-fichier-latex-avec-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.mathweb.fr\/euclide\/"},{"@type":"ListItem","position":2,"name":"Cr\u00e9er un fichier 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\/1157","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=1157"}],"version-history":[{"count":0,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/posts\/1157\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/media\/1161"}],"wp:attachment":[{"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/media?parent=1157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/categories?post=1157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mathweb.fr\/euclide\/wp-json\/wp\/v2\/tags?post=1157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}