gpt4 book ai didi

org-mode - 在 org 文件中包含代码片段

转载 作者:行者123 更新时间:2023-12-04 18:03:50 30 4
gpt4 key购买 nike

我想使用 org 模式来写一本技术书籍。我正在寻找一种将外部文件中的现有代码插入到 babel 代码块中的方法,该代码块在导出为 pdf 时会提供很好的格式。

例如

#+BEGIN_SRC python "./code/foo.py" 
# insert_line (45,50)
#+END_SRC

然后会给我相当于 foo.py 中第 45 行到第 50 行的以下内容
#+BEGIN_SRC python
def times_two(x):
y = x*2
return y

print times_two(5)
#+END_SRC

反正有这样做吗?

最佳答案

我认为这样的事情可以工作:

#+include: "./code/foo.py" :lines "45-50"

手册链接: http://orgmode.org/manual/Include-files.html

关于org-mode - 在 org 文件中包含代码片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36605951/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com