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?

  • just use \input{table} and each user arrange that their Dropbox is in the tex input path. – David Carlisle Sep 2 at 21:15
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}
| improve this answer | |
  • 1
    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 3 at 6: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 3 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.