
저는 공동 프로젝트를 진행 중이며 Dropbox를 사용하여 공유 파일을 저장합니다. tex로 만든 테이블(table.tex라고 함)을 tex 문서에 \입력하고 싶지만 table.tex는 컴퓨터마다 Dropbox 내에서 파일 경로가 다릅니다. 예를 들어, 한 사람의 모습은 다음과 같습니다.
/Users/usernameA/Dropbox/folder1/tables/table.tex
그리고 다른 사람은 아마도
/Users/usernameB/Dropbox/folderx/folder1/tables/table.tex
이것이 우리가 해왔던 일입니다:
\newcommand{\rootPath}{/Users/usernameA/Dropbox/folder1/tables
%\newcommand{\rootPath}{/Users/usernameB/Dropbox/folderX/folder1/tables
문서를 다시 컴파일하는 사람은 다른 사람의 경로와 나중에 문서에 주석을 달 수 있습니다.
\input{"\rootpath/table.tex"}
다른 컴퓨터의 다른 폴더에서 table.tex에 액세스하는 더 간단한 방법이 있습니까?
답변1
다음 솔루션은 id
명령을 호출하여 현재 UNIX 시스템의 사용자 이름을 가져와서 \username
. (등록되지 않은) 외부 명령이므로 --shell-escape
LaTeX 컴파일러에 플래그를 추가해야 합니다 .id
여기를 보아라:--shell-escape는 무엇을 합니까?
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\newcommand{\username}{}
\msg_new:nnn {doc} {noshell} {no~shell~avaliable-please~enable~shell~escape!}
\msg_new:nnn {doc} {nousername} {unable~to~extract~user~name}
\cs_generate_variant:Nn \regex_extract_once:nnN {nVN}
% determine if shell is avaliable
\sys_if_shell_unrestricted:TF {
% run id command
\sys_get_shell:nnN {id} {} \l_tmpa_tl
% use regex to extract user name
\regex_extract_once:nVN {uid=[0-9]*\((.*?)\)} \l_tmpa_tl \l_tmpa_seq
\int_compare:nTF {\seq_count:N \l_tmpa_seq < 2} {
\msg_error:nn {doc} {nousername}
}{
% extract user name
\tl_gset:Nx \username {\seq_item:Nn \l_tmpa_seq {2}}
}
} {
\msg_error:nn {doc} {noshell}
}
\ExplSyntaxOff
\begin{document}
\newcommand{\rootpath}{/Users/\username/Dropbox/folder1/tables}
\rootpath
\end{document}
답변2
내 의견을 자세히 설명하자면, 기본 tex 파일이 와 동일한 디렉토리에 있으면 folder1
모든 사용자가 \input{folder1/tables/table}
. 이를 위한 주요 요구 사항은 전체 프로젝트가 포함된 폴더를 공유해야 한다는 것입니다. (그리고 도 \input
필요하지 않습니다 .)"
.tex