{"action":"opened","issue":{"url":"https://api.github.com/repos/SublimeText/LaTeXTools/issues/630","labels_url":"https://api.github.com/repos/SublimeText/LaTeXTools/issues/630/labels{/name}","comments_url":"https://api.github.com/repos/SublimeText/LaTeXTools/issues/630/comments","events_url":"https://api.github.com/repos/SublimeText/LaTeXTools/issues/630/events","html_url":"https://github.com/SublimeText/LaTeXTools/issues/630","id":122410449,"number":630,"title":"Main file defined in project settings (TeXroot) depends on cwd if relative paths are used","user":{"login":"neelabhg","id":846827,"avatar_url":"https://avatars.githubusercontent.com/u/846827?v=3","gravatar_id":"","url":"https://api.github.com/users/neelabhg","html_url":"https://github.com/neelabhg","followers_url":"https://api.github.com/users/neelabhg/followers","following_url":"https://api.github.com/users/neelabhg/following{/other_user}","gists_url":"https://api.github.com/users/neelabhg/gists{/gist_id}","starred_url":"https://api.github.com/users/neelabhg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neelabhg/subscriptions","organizations_url":"https://api.github.com/users/neelabhg/orgs","repos_url":"https://api.github.com/users/neelabhg/repos","events_url":"https://api.github.com/users/neelabhg/events{/privacy}","received_events_url":"https://api.github.com/users/neelabhg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-16T02:00:49Z","updated_at":"2015-12-16T02:00:49Z","closed_at":null,"body":"#### Problem\r\nIn the case when:\r\n\r\n1. The main file is defined in project settings using a relative path, and\r\n2. The source file, from which a command is invoked, is in a directory different than that of the main TeX root file (for example, `chapters/ch1.tex`),\r\n\r\nthe following issues may be experienced:\r\n\r\n* If the `TeXroot` is not relative to the source file (for example `TeXroot: \"main.tex\"`), then the main file is not found, and the source file is taken to be the root file, causing errors during compilation. Viewing the PDF file also does not work, because it tries to launch the wrong PDF (for example, `chapters/ch1.pdf`, which most likely does not exist).\r\n\r\n* If the `TeXroot` is relative to the source file (for example, `TeXroot: \"../main.tex\"`), then the main file is found and compilation succeeds, but when launching the PDF viewer after compilation, the main file is not found (because the cwd at that point is that of the root file itself), and so the wrong pdf is launched (for example, `chapters/ch1.pdf`). Viewing the PDF file directly, however, does work because the main file is set correctly.\r\n\r\n#### Workaround\r\nCurrently, the solution is to use an absolute path in the project settings, but it's not ideal because the `.sublime-project` file is usually checked in to version control.\r\n\r\n#### Possible solution\r\nThe ideal solution would be to resolve paths relative to the project directory, similar to the behavior of the `folders` section of [Sublime Text project definition files](https://www.sublimetext.com/docs/2/projects.html).\r\n\r\nOne way to do this could be to use the project directory as the base directory in [`getTeXRoot.py#L26`](https://github.com/SublimeText/LaTeXTools/blob/6bb8ab9cfcb3fc4dcf1a47c8d6c1ea0db428f95b/getTeXRoot.py#L26). So, instead of\r\n```py\r\nroot = os.path.abspath(view.settings().get('TEXroot'))\r\n```\r\n\r\nwe can have something like\r\n```py\r\nroot = os.path.abspath(os.path.join(get_project_root(view), view.settings().get('TEXroot')))\r\n```\r\n\r\nwhere\r\n```py\r\ndef get_project_root(view):\r\n    if (using ST3):\r\n          return os.path.dirname(view.window().project_file_name())\r\n\r\n```\r\n"}}