Forgot password?
 Create new account
View 156|Reply 1

公式环境输出源码

[Copy link]

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2023-4-30 07:16:45 |Read mode
Last edited by hbghlyj at 2023-5-1 21:41:00
  1. \documentclass{article}
  2. \def\[#1\]{\texttt{\detokenize{\[#1\]}}}
  3. \def\(#1\){\texttt{\detokenize{\(#1\)}}}
  4. \begin{document}
  5. Some text before.
  6. \[\frac12\]
  7. \(\frac12\)
  8. Some text after.
  9. \end{document}
Copy the Code

可以看到\(,\),\[,\]被重新定义后输出源码.
  1. \documentclass{article}
  2. \usepackage{amsmath,verbatim}
  3. \newcommand\VerbMath[1]{\renewenvironment{#1}{\verbatim\symbol{92}begin\{#1\}}{\symbol{92}end\{#1\}\endverbatim}}
  4. \VerbMath{equation}
  5. \VerbMath{equation*}
  6. \VerbMath{align}
  7. \VerbMath{align*}
  8. \VerbMath{alignat*}
  9. \VerbMath{gather}
  10. \VerbMath{gather*}
  11. \VerbMath{cases}
  12. \VerbMath{array}
  13. \VerbMath{matrix}
  14. \VerbMath{pmatrix}
  15. \VerbMath{eqnarray}
  16. \VerbMath{eqnarray*}
  17. \begin{document}
  18. Some text before.
  19. \begin{equation}
  20. \frac12
  21. \end{equation}
  22. Some text after.
  23. \end{document}
Copy the Code
可以看到equation环境被重新定义后输出源码.

问题:
如何重新定义$,$$使它们输出源码

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2023-4-30 08:52:58
参考tex.stackexchange.com/questions/59980
  1. \documentclass{article}
  2. \catcode`$=\active
  3. \makeatletter
  4. \protected\def${\@ifnextchar$\@doubledollar\@singledollar}
  5. \def\@doubledollar$#1$${\texttt{\detokenize{$$#1$$}}}
  6. \def\@singledollar#1${\texttt{\detokenize{$#1$}}}
  7. \makeatother
  8. \begin{document}
  9. Some text before.
  10. $$\frac12$$
  11. $\frac12$
  12. Some text after.
  13. \end{document}
Copy the Code

手机版Mobile version|Leisure Math Forum

2025-4-20 21:59 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list