Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于“文件的组织方式”一节的错误例子的修改建议 #58

Closed
bro-sin opened this issue Jan 28, 2021 · 1 comment
Closed

Comments

@bro-sin
Copy link

bro-sin commented Jan 28, 2021

问题修改建议

第一章1.6 文件的组织方式中给出的例子应当修改修改为去掉.tex后缀。望采纳、更新,感谢!

详细说明

下面是该问题的详细说明

lshort-zh-cn的第一章的1.6 文件的组织方式有提到\include命令的用法:

LATEX 提供了命令 \include 用来在源代码里插入文件:
\include{⟨filename⟩}
⟨filename⟩ 为文件名,如果和要编译的主文件不在一个目录中,则要加上相对或绝对路径,例如:
\include{chapters/a.tex} % 相对路径
\include{/home/Bob/file.tex} % Linux/macOS 绝对路径
\include{D:/file.tex} % Windows 绝对路径,用正斜线

而事实上,通过如下尝试:
在一个空文件夹下面建立两个文件,分别是:

%filea.tex
\documentclass{article}
\begin{document}
This is a \LaTeX \ file.
\include{fileb.tex}
%\include{fileb}
\end{document}
%fileb.tex
This is another \LaTeX \ file.

执行命令pdflatex filea.tex,输出的只有filea.tex文件的内容。
filea.tex修改为:

%filea.tex
\documentclass{article}
\begin{document}
This is a \LaTeX \ file.
%\include{fileb.tex}
\include{fileb}
\end{document}

再执行命令pdflatex filea.tex,就得到了同时包含filea.texfileb.tex文件内容的输出结果。

可以发现,在使用相对路径时,不应当使用\include{chapters/a.tex}这种形式的命令,而应当改为 \include{chapters/a}这种形式,否则编译不出a.tex文件中的内容。

同时,在查阅了lshort原文后,注意到,在Chapter 1的1.8 Big Projects中是这么介绍的:

When working on big documents, you might want to split the input file into several parts. LATEX has two commands that help you to do that.
\include{filename}
Use this command in the document body to insert the contents of another file named filename.tex. Note that LATEX will start a new page before processing the material input from filename.tex.

可以看出,虽然原文没有给出使用示例,但是确实是指的是使用\include{chapters/a}这种形式的命令。

相关问题

出于对上述错误的思考,我又尝试了另外一种,就是使用绝对路径,但结果令人惊讶,无论我是否带后缀,\include命令都无法编译出来;而使用\input命令,无论我是否带后缀,都能编译出理想的效果。

参考链接

  1. 我本来遇到的问题是这个:https://wenda.latexstudio.net/q-5285.html
  2. lshort原文对应章节文档:https://github.com/oetiker/lshort/blob/master/book/src/things.tex
@stone-zeng
Copy link
Member

在 LaTeX 2020-10-01 中,\include\includeonly 会去除文件名结尾的 .tex(同时也能正确处理文件名中包含空格的情况),但在 ltnews 中并没有指出这一点(空格是说了的)。

具体代码:

https://github.com/latex3/latex2e/blob/572e060e935419c1ffc9edbbcca2914f6fd0cd13/base/ltfiles.dtx#L708-L719

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants