是否有可能编写自己的“包"?对于LaTeX? [英] Is it possible to write own "packages" for LaTeX?
问题描述
作为一名程序员,我想知道是否可以为LaTeX创建自己的软件包.我需要类似著名的列表"程序包的东西,但更能满足我的需求.我正在寻找一个清单解决方案,该解决方案需要提防诸如
As a programmer, I wonder if I could create my own package for LaTeX. I need something like that famous "listings" package, but something that is much more capable for my needs. I look for a listings solution that would watch out for a comment line like
// BEGIN LISTING 3122
// END LISTING 3122
不突出显示语法,但是智能地支持制表符缩进.然后,该软件包将与文件名或路径一起使用,遍历各行,然后仅复制感兴趣的代码段.
No syntax highlighting, but intelligent support for tab indents. That package then would be used with a file name or path, walk through the lines and copy out just the snippets of interest.
我100%确信市场上绝对没有这样的东西.所以我想为LaTeX编程.如果可能的话.我不知道如何以及使用哪种编程语言/IDE.我将从哪里开始寻找?
I am 100% sure there is absolutely nothing like this on the market. So I want to program it for LaTeX. If that's possible. I have no idea how and what programming language / IDE. Where would I start looking?
推荐答案
当然可以,但这在TeX编程语言中并不简单.我现在没有时间对其进行编码,但是这里有一个算法.我建议在comp.text.tex上询问更具体的LaTeX编程建议.
This is certainly possible, but it is non-trivial in the TeX programming language. I don't have time to code it up at the moment but here's an algorithm; I suggest asking on comp.text.tex for more specific LaTeX programming advice.
- 在本地将所有特殊字符的猫码设置为其他"(
\dospecials
),并开始逐行(\read
)读入输入文件
对于每行 - ,请比较该行的第一个标记,但要比较多个标记(对
\if
或\ifx
的某些迭代使用;可能有一个使它更容易使用的包,例如stringstrings或xstring)- 在默认状态下,扔掉输入行并阅读下一行
- 除非它是
// BEGIN LISTING
,在这种情况下,请将每行保存到一个宏中(类似于\g@addto@macro
) - 直到它是
// END LISTING
,显然
- Locally set all catcodes of special chars to "other" (
\dospecials
) and start reading in the input file line by line (\read
) - for each line compare the first however many tokens of the line (some iterative use of
\if
or\ifx
; there might be a package to make this easier such as stringstrings or xstring)- in the default state throw away the input line and read the next
- unless it's
// BEGIN LISTING
, in which case save each line into a macro (something like\g@addto@macro
) - until it's
// END LISTING
, obviously
按主题划分的TeX 是这类工作的很好的参考指南.
TeX by Topic is a good reference guide for this sort of work.
这篇关于是否有可能编写自己的“包"?对于LaTeX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!