
Overleaf를 사용하여 일부 파일을 편집하고 있습니다.
LaTeX에서 파일의 일부를 다른 파일에 연결하는 명령을 설정할 수 있습니까? 내부의 모든 내용을 동일한 프로젝트의 다른 외부 파일에 정확히 복사한다는 의미입니다. {}
(모든 변경 사항을 거기에 적용하면 해당 섹션을 두 번째 파일에 복사하여 붙여넣을 필요가 없습니다.)
예를 들어, 및 .tex
이라는 이름의 두 개의 파일이 있습니다 . 내가 기대하는 것은 다음과 같습니다.A.tex
B.tex
A.tex
\documentclass{article}
\newcommand\MycommandA[1]{\textcolor{red}{#1}}
\begin{document}
\MycommandA{This is a text}
\end{document}
그리고 B.tex
나는 다음과 같습니다
\documentclass{article}
\newcommand\MycommandA[1]{\textcolor{red}{#1}}
\begin{document}
\MycommandA{This is text}
\end{document}
따라서 로 \MycommandA{This is a text}
변경 하면 LaTeX가 자동으로 .A.tex
\MycommandA{This is a book}
B.tex
답변1
많은 데스크탑 편집기는 다중 파일 편집을 지원하지만 Overleaf는 그렇지 않다고 생각합니다. 라텍스는 소스를 편집하지 않기 때문에 실제로 라텍스 문제는 아닙니다.
라텍스 방식은 아래 예와 같이 공유 텍스트나 명령 텍스트를 하나의 파일에 두는 것입니다.
mycommands.tex
\newcommand\MycommandA[1]{\textcolor{red}{#1}}
\newcommand\textA{This is a shared text}
이와 같은 작은 조각의 경우 This is a shared text
위와 같은 명령을 사용하는 것이 편리합니다. 전체 섹션과 같은 더 큰 조각의 경우 별도의 파일을 사용할 수 있습니다.
그러면 텍스트가 한 곳에만 나타나며 귀하의 A.tex
and B.tex
는 다음과 같이 보일 수 있습니다.
에이텍스
\documentclass{article}
\input{mycommands}
\begin{document}
\section{Intro for A}% not shared
\MycommandA{\textA}% shared
\MycommandA{Text just in A but using the shared command}
\input{sharedsec}% shared
\end{document}
비텍스
\documentclass{report}
\input{mycommands}
\begin{document}
\section{Intro for B}% not shared
\MycommandA{\textA}% shared
Some text just in B.
\input{sharedsec}% shared
\end{document}
sharedsec.tex
\section{Something}
This text just appears once in the source but appears in A and B