0

I am working on a collaborative project and we use Dropbox to store our shared files. I would like to \input a table made in tex (called table.tex) to a tex document but table.tex has a different file path within Dropbox on different computers. For example, one person's might look like this

/Users/usernameA/Dropbox/folder1/tables/table.tex

and the other's might be

/Users/usernameB/Dropbox/folderx/folder1/tables/table.tex

This is what we've been doing:

\newcommand{\rootPath}{/Users/usernameA/Dropbox/folder1/tables
%\newcommand{\rootPath}{/Users/usernameB/Dropbox/folderX/folder1/tables

Whoever is recompiling the document comments out other people's paths and later in the document

\input{"\rootpath/table.tex"}

Is there a simpler way to access table.tex from different folders on different computers?

sara
  • 1
  • 1
    just use \input{table} and each user arrange that their Dropbox is in the tex input path. – David Carlisle Sep 02 '20 at 21:15
  • I've just shared the Dropbox folder with the collaborators. Then the only requirement is that everything needs to be relative paths. – Teepeemm May 21 '23 at 18:35

2 Answers2

0

The following solution calls id command to get the user name of current UNIX system and stores it in \username. You need to add --shell-escape flag to your LaTeX compiler because id is an (unregistered) external command.

See here: What does --shell-escape do?

\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}

Alan Xiang
  • 5,227
  • 2
    I wouldn't activate shell-escape only to get one path that one could simply store in some config file and load. – Ulrike Fischer Sep 03 '20 at 06:32
  • @UlrikeFischer I agree that security is a big concern. What I like about LaTeX is that it is both a typesetting language and a generic programming language. Despite that fact that the latter perspective is often overlooked, we should all agree LaTeX cannot reach its current status without its Turing completeness. If you think about it, LaTeX can be one of the several programming languages that do not have shell access by default! It still sounds a little unfair that one can trust a software installer or jupyter notebook downloaded from the Internet, but not a TeX file. – Alan Xiang Sep 03 '20 at 18:35
0

To elaborate on my comment: if the main tex file is in the same directory as folder1, then all users can have \input{folder1/tables/table}. The main requirement for this to happen is that you have shared the folder containing the entire project. (And \input doesn't need " nor .tex.)

Teepeemm
  • 6,708