{"id":222079,"date":"2024-05-11T18:51:21","date_gmt":"2024-05-11T10:51:21","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/222079.html"},"modified":"2024-05-11T18:51:25","modified_gmt":"2024-05-11T10:51:25","slug":"%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e4%b8%80%e4%b8%aalatex%e8%a1%8c%e5%86%85%e4%bb%a3%e7%a0%81%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/222079.html","title":{"rendered":"\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2aLaTeX\u884c\u5185\u4ee3\u7801\u73af\u5883"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25141908\/9373d87f-8a85-4903-a2b8-d609f6c06f8f.webp\" alt=\"\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2aLaTeX\u884c\u5185\u4ee3\u7801\u73af\u5883\" \/><\/p>\n<p><p>\u5728LaTeX\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u884c\u5185\u4ee3\u7801\u73af\u5883\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5176\u4e2d\u5305\u62ec<strong>\u4f7f\u7528<code>lstinline<\/code>\u6307\u4ee4\u3001\u5229\u7528<code>minted<\/code>\u5305\u4ee5\u53ca\u5b9a\u4e49\u81ea\u5df1\u7684\u5b8f<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u4f7f\u7528<code>lstinline<\/code>\u6307\u4ee4<\/strong>\u662f\u6700\u4e3a\u76f4\u63a5\u548c\u5e38\u89c1\u7684\u65b9\u5f0f\uff0c\u80fd\u591f\u5728\u6587\u6863\u4e2d\u76f4\u89c2\u5730\u5c55\u793a\u4ee3\u7801\u7247\u6bb5\u800c\u4e0d\u5f71\u54cd\u5468\u56f4\u7684\u6587\u672c\u5e03\u5c40\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528<code>LSTINLINE<\/code>\u6307\u4ee4<\/h3>\n<\/p>\n<p><p><code>lstinline<\/code>\u662f<code>listings<\/code>\u5b8f\u5305\u63d0\u4f9b\u7684\u4e00\u4e2a\u6307\u4ee4\uff0c\u7528\u4e8e\u5728\u6587\u672c\u4e2d\u76f4\u63a5\u63d2\u5165\u683c\u5f0f\u5316\u540e\u7684\u4ee3\u7801\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u6587\u6863\u7684\u524d\u5bfc\u533a\uff08\u5373<code>\\begin{document}<\/code>\u4e4b\u524d\u7684\u90e8\u5206\uff09\u91cc\u4f7f\u7528<code>\\usepackage{listings}<\/code>\u547d\u4ee4\u6765\u8c03\u7528<code>listings<\/code>\u5b8f\u5305\u3002\u7136\u540e\uff0c\u5728\u6587\u672c\u4e2d\u5c31\u53ef\u4ee5\u901a\u8fc7<code>lstinline<\/code>\u6307\u4ee4\u63d2\u5165\u884c\u5185\u4ee3\u7801\u4e86\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u8981\u5728\u6587\u672c\u4e2d\u63d2\u5165C\u8bed\u8a00\u7684<code>return 0;<\/code>\u4ee3\u7801\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-latex\">\u6211\u4eec\u7684\u7a0b\u5e8f\u4ee5\\lstinline|return 0;|\u7ed3\u675f\u3002<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c<code>return 0;<\/code>\u8fd9\u90e8\u5206\u5c06\u4ee5<code>listings<\/code>\u5b8f\u5305\u9884\u8bbe\u7684\u4ee3\u7801\u6837\u5f0f\u663e\u793a\uff0c\u4e0e\u5468\u56f4\u7684\u6587\u672c\u533a\u5206\u5f00\u6765\uff0c\u4ee5\u66f4\u597d\u5730\u6307\u51fa\u8fd9\u662f\u4e00\u6bb5\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>\u8bbe\u7f6e<code>lstinline<\/code>\u6837\u5f0f<\/h4>\n<\/p>\n<p><p><code>listings<\/code>\u5b8f\u5305\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u4ee3\u7801\u7684\u683c\u5f0f\uff0c\u5305\u62ec\u5b57\u4f53\u3001\u989c\u8272\u7b49\u3002\u8fd9\u4e9b\u8bbe\u7f6e\u53ef\u4ee5\u901a\u8fc7<code>\\lstset{...}<\/code>\u547d\u4ee4\u5b8c\u6210\u3002\u4f8b\u5982\uff0c\u82e5\u8981\u8bbe\u7f6e\u6240\u6709\u4ee3\u7801\u7684\u5b57\u4f53\u4e3a\u6253\u5b57\u673a\u5b57\u4f53\uff0c\u5e76\u4e14\u5173\u952e\u5b57\u4e3a\u84dd\u8272\uff0c\u53ef\u4ee5\u8fd9\u6837\u8bbe\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-latex\">\\lstset{basicstyle=\\ttfamily, keywordstyle=\\color{blue}}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e4b\u540e\uff0c\u6240\u6709\u901a\u8fc7<code>lstinline<\/code>\u63d2\u5165\u7684\u4ee3\u7801\u90fd\u4f1a\u91c7\u7528\u8fd9\u4e00\u683c\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u8ba9\u884c\u5185\u4ee3\u7801\u4e0e\u666e\u901a\u6587\u672c\u660e\u663e\u533a\u5206\u5f00\u6765\uff0c\u63d0\u9ad8\u4e86\u6587\u6863\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5229\u7528<code>MINTED<\/code>\u5305<\/h3>\n<\/p>\n<p><p><code>minted<\/code>\u662f\u53e6\u4e00\u4e2a\u5f3a\u5927\u7684\u4ee3\u7801\u9ad8\u4eae\u5b8f\u5305\uff0c\u5b83\u57fa\u4e8ePython\u7684Pygments\u5e93\u3002\u4e0e<code>listings<\/code>\u5b8f\u5305\u76f8\u6bd4\uff0c<code>minted<\/code>\u80fd\u63d0\u4f9b\u66f4\u4e3a\u4e30\u5bcc\u7684\u8bed\u8a00\u652f\u6301\u548c\u66f4\u6f02\u4eae\u7684\u4ee3\u7801\u9ad8\u4eae\u6548\u679c\u3002\u4e0d\u8fc7\uff0c\u4f7f\u7528<code>minted<\/code>\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u52a0\u4e0a<code>-shell-escape<\/code>\u9009\u9879\uff0c\u5e76\u786e\u4fdd\u7cfb\u7edf\u4e0a\u5df2\u5b89\u88c5Python\u548cPygments\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5\u548c\u4f7f\u7528<code>minted<\/code><\/h4>\n<\/p>\n<p><p>\u5148\u786e\u4fdd\u7cfb\u7edf\u5b89\u88c5\u4e86Python\u548cPygments\uff0c\u7136\u540e\u5728LaTeX\u6587\u6863\u7684\u524d\u5bfc\u533a\u8c03\u7528<code>minted<\/code>\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-latex\">\\usepackage{minted}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u672c\u4e2d\u4f7f\u7528\u884c\u5185\u4ee3\u7801\u65f6\uff0c\u53ef\u4ee5\u7528<code>\\mintinline{language}{code}<\/code>\u7684\u5f62\u5f0f\uff0c\u5176\u4e2d<code>language<\/code>\u662f\u4ee3\u7801\u7684\u8bed\u8a00\uff0c<code>code<\/code>\u662f\u4ee3\u7801\u6587\u672c\u3002\u6bd4\u5982\uff0c\u8981\u63d2\u5165Python\u7684<code>import numpy as np<\/code>\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-latex\">\u6211\u4eec\u901a\u5e38\u4f1a\u8fd9\u6837\u5bfc\u5165NumPy\u5e93\uff1a\\mintinline{python}{import numpy as np}\u3002<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0e<code>lstinline<\/code>\u7c7b\u4f3c\uff0c<code>minted<\/code>\u4e5f\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u4ee3\u7801\u6837\u5f0f\uff0c\u4f46\u5176\u6837\u5f0f\u7684\u5b9a\u5236\u548c\u5e94\u7528\u65b9\u5f0f\u66f4\u52a0\u7075\u6d3b\u548c\u4e30\u5bcc\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5b9a\u4e49\u81ea\u5df1\u7684\u5b8f<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u60f3\u8981\u5b8c\u5168\u63a7\u5236\u884c\u5185\u4ee3\u7801\u663e\u793a\u6837\u5f0f\u7684\u7528\u6237\uff0c\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5df1\u7684\u5b8f\u53ef\u80fd\u662f\u6700\u597d\u7684\u9009\u62e9\u3002LaTeX\u5141\u8bb8\u7528\u6237\u901a\u8fc7<code>\\newcommand<\/code>\u547d\u4ee4\u6765\u5b9a\u4e49\u65b0\u7684\u547d\u4ee4\uff0c\u4ee5\u6ee1\u8db3\u7279\u6b8a\u7684\u683c\u5f0f\u8981\u6c42\u3002<\/p>\n<\/p>\n<p><h4>\u81ea\u5b9a\u4e49\u5b8f\u7684\u6b65\u9aa4<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u786e\u5b9a\u683c\u5f0f\u9700\u6c42<\/strong>\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u660e\u786e\u4f60\u5e0c\u671b\u884c\u5185\u4ee3\u7801\u5982\u4f55\u663e\u793a\uff0c\u6bd4\u5982\u5b57\u4f53\u3001\u989c\u8272\u548c\u80cc\u666f\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199<code>\\newcommand<\/code>\u547d\u4ee4<\/strong>\uff1a\u57fa\u4e8e\u683c\u5f0f\u9700\u6c42\uff0c\u4f7f\u7528<code>\\newcommand<\/code>\u5b9a\u4e49\u4e00\u4e2a\u65b0\u547d\u4ee4\u3002\u6bd4\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u5c06\u4ee3\u7801\u6587\u5b57\u8bbe\u4e3a\u84dd\u8272\u7684\u547d\u4ee4<code>mycode<\/code>\uff0c\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-latex\">\\newcommand{\\mycode}[1]{{\\color{blue}\\texttt{#1}}}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e4b\u540e\uff0c\u53ea\u9700\u5728\u6587\u6863\u4e2d\u7528<code>\\mycode{code}<\/code>\u7684\u5f62\u5f0f\u63d2\u5165\u4ee3\u7801\uff0c\u4ee3\u7801\u5c06\u4ee5\u6307\u5b9a\u7684\u6837\u5f0f\u663e\u793a\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u5f7b\u5e95\u638c\u63e1<strong>\u5229\u7528<code>minted<\/code>\u5305<\/strong>\u7684\u65b9\u6cd5\uff0c\u8ba9\u6211\u4eec\u6df1\u5165\u4e86\u89e3\u5176\u8bbe\u7f6e\u548c\u9ad8\u7ea7\u7528\u6cd5\u3002<code>minted<\/code>\u63d0\u4f9b\u4e86\u6781\u5927\u7684\u7075\u6d3b\u6027\u7528\u4e8e\u4ee3\u7801\u9ad8\u4eae\u663e\u793a\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u81ea\u5b9a\u4e49\u4ee3\u7801\u5757\u80cc\u666f\u3001\u884c\u53f7\u663e\u793a\u3001\u4ee3\u7801\u6298\u884c\u7b49\u3002\u7528\u6237\u8fd8\u53ef\u4ee5\u6307\u5b9a\u5168\u5c40\u7684<code>minted<\/code>\u8bbe\u7f6e\uff0c\u6216\u662f\u9488\u5bf9\u7279\u5b9a\u4ee3\u7801\u5757\u505a\u51fa\u7ec6\u8282\u4e0a\u7684\u8c03\u6574\uff0c\u4ee5\u5b9e\u73b0\u6700\u4f73\u7684\u663e\u793a\u6548\u679c\u3002\u901a\u8fc7\u6df1\u5165\u5b66\u4e60\u548c\u5b9e\u8df5<code>minted<\/code>\u5305\u7684\u9ad8\u7ea7\u7279\u6027\uff0c\u53ef\u4ee5\u4f7fLaTeX\u6587\u6863\u4e2d\u7684\u4ee3\u7801\u5c55\u793a\u66f4\u52a0\u4e13\u4e1a\u548c\u7f8e\u89c2\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. LaTeX\u884c\u5185\u4ee3\u7801\u73af\u5883\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\nLaTeX\u884c\u5185\u4ee3\u7801\u73af\u5883\u662f\u4e00\u79cd\u7528\u4e8e\u63d2\u5165\u8ba1\u7b97\u673a\u4ee3\u7801\u7247\u6bb5\u7684\u65b9\u5f0f\uff0c\u5b83\u4f7f\u5f97\u4ee3\u7801\u80fd\u591f\u4ee5\u7b49\u5bbd\u5b57\u4f53\u7684\u65b9\u5f0f\u663e\u793a\u5728\u6587\u672c\u4e2d\uff0c\u5e76\u4e14\u4e0d\u4f1a\u88abLaTeX\u89e3\u91ca\u4e3a\u666e\u901a\u6587\u672c\u3002\u884c\u5185\u4ee3\u7801\u73af\u5883\u901a\u5e38\u7528\u4e8e\u5f15\u7528\u51fd\u6570\u3001\u53d8\u91cf\u540d\u6216\u547d\u4ee4\u7b49\u76f8\u5173\u7684\u4ee3\u7801\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684LaTeX\u884c\u5185\u4ee3\u7801\u73af\u5883\uff1f<\/strong><br \/>\n\u8981\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684LaTeX\u884c\u5185\u4ee3\u7801\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528LaTeX\u7684listings\u5b8f\u5305\u3002\u9996\u5148\uff0c\u9700\u8981\u5f15\u5165\u8be5\u5b8f\u5305\uff08\u4f7f\u7528\\usepackage{listings}\u547d\u4ee4\uff09\u3002\u7136\u540e\uff0c\u5728\u5bfc\u8a00\u533a\u6216\u5408\u9002\u7684\u5730\u65b9\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u884c\u5185\u4ee3\u7801\u73af\u5883\uff1a<br \/>\n\\lstnewenvironment{myinlinecode}{\\lstset{basicstyle=\\ttfamily}}{}<br \/>\n\u5176\u4e2d\uff0cmyinlinecode\u662f\u81ea\u5b9a\u4e49\u73af\u5883\u7684\u540d\u79f0\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u4fee\u6539\u3002\u901a\u8fc7\u5728\u6587\u672c\u4e2d\u4f7f\u7528\\begin{myinlinecode}\u548c\\end{myinlinecode}\u547d\u4ee4\uff0c\u53ef\u4ee5\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\u63d2\u5165\u884c\u5185\u4ee3\u7801\u3002<\/p>\n<p><strong>3. \u884c\u5185\u4ee3\u7801\u73af\u5883\u6709\u54ea\u4e9b\u5e38\u7528\u7684\u9009\u9879\uff1f<\/strong><br \/>\n\u884c\u5185\u4ee3\u7801\u73af\u5883\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u9009\u9879\u6765\u63a7\u5236\u4ee3\u7801\u7684\u663e\u793a\u6548\u679c\u3002\u4e00\u4e9b\u5e38\u7528\u7684\u9009\u9879\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>basicstyle<\/code>\uff1a\u6307\u5b9a\u4ee3\u7801\u7684\u57fa\u672c\u5b57\u4f53\u6837\u5f0f\uff0c\u53ef\u4ee5\u662f\u7b49\u5bbd\u5b57\u4f53\uff08\u5982\\ttfamily\uff09\u6216\u5176\u4ed6\u81ea\u5b9a\u4e49\u7684\u5b57\u4f53\u3002<\/li>\n<li><code>keywordstyle<\/code>\uff1a\u6307\u5b9a\u5173\u952e\u5b57\u7684\u5b57\u4f53\u6837\u5f0f\uff0c\u901a\u5e38\u4f7f\u7528\u7c97\u4f53\u6765\u5f3a\u8c03\u3002<\/li>\n<li><code>commentstyle<\/code>\uff1a\u6307\u5b9a\u6ce8\u91ca\u7684\u5b57\u4f53\u6837\u5f0f\uff0c\u4ee5\u4fbf\u4e0e\u4ee3\u7801\u533a\u5206\u5f00\u3002<\/li>\n<li><code>language<\/code>\uff1a\u6307\u5b9a\u4ee3\u7801\u6240\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4ee5\u4fbf\u6b63\u786e\u5730\u9ad8\u4eae\u663e\u793a\u5173\u952e\u5b57\u548c\u8bed\u6cd5\u3002<\/li>\n<li><code>numbers<\/code>\uff1a\u5c06\u4ee3\u7801\u884c\u7f16\u53f7\u663e\u793a\u5728\u6bcf\u884c\u5f00\u5934\u3002<br \/>\n\u8fd9\u4e9b\u9009\u9879\u53ef\u4ee5\u901a\u8fc7\u5728\u5b9a\u4e49\u884c\u5185\u4ee3\u7801\u73af\u5883\u65f6\u4f7f\u7528<code>\\lstset<\/code>\u547d\u4ee4\u6765\u8bbe\u7f6e\uff0c\u4e5f\u53ef\u4ee5\u5728\u4f7f\u7528\u884c\u5185\u4ee3\u7801\u73af\u5883\u65f6\u4f5c\u4e3a\u53ef\u9009\u53c2\u6570\u4f20\u9012\u7ed9<code>\\begin{myinlinecode}<\/code>\u547d\u4ee4\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u5728LaTeX\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u884c\u5185\u4ee3\u7801\u73af\u5883\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5176\u4e2d\u5305\u62ec\u4f7f\u7528lstinline\u6307\u4ee4\u3001\u5229\u7528minted\u5305 [&hellip;]","protected":false},"author":3,"featured_media":222087,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/222079"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=222079"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/222079\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/222087"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=222079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=222079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=222079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}