Navigation Menu

Skip to content

Commit

Permalink
use helper R function for getting tinytex bin
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Oct 1, 2019
1 parent ffdce13 commit cc7a5cc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
18 changes: 12 additions & 6 deletions src/cpp/core/include/core/system/Xdg.hpp
Expand Up @@ -31,16 +31,22 @@ namespace xdg {
* All of these can be configured with environment variables as described below.
*/

// Returns the RStudio XDG user config directory. On Unix-alikes, this is ~/.config/rstudio, or
// XDG_CONFIG_HOME.
// Returns the RStudio XDG user config directory.
//
// On Unix-alikes, this is ~/.config/rstudio, or XDG_CONFIG_HOME.
// On Windows, this is 'FOLDERID_RoamingAppData' (typically 'AppData/Roaming').
FilePath userConfigDir();

// Returns the RStudio XDG user data directory. On Unix-alikes, this is ~/.local/share/rstudio, or
// XDG_DATA_HOME
// Returns the RStudio XDG user data directory.
//
// On Unix-alikes, this is ~/.local/share/rstudio, or XDG_DATA_HOME.
// On Windows, this is 'FOLDERID_LocalAppData' (typically 'AppData/Local').
FilePath userDataDir();

// Returns the RStudio XDG system config directory. On Unix-alikes, this is /etc/rstudio, or
// XDG_CONFIG_DIRS
// Returns the RStudio XDG system config directory.
//
// On Unix-alikes, this is /etc/rstudio, XDG_CONFIG_DIRS.
// On Windows, this is 'FOLDERID_ProgramData' (typically 'C:/ProgramData').
FilePath systemConfigDir();

} // namespace xdg
Expand Down
26 changes: 12 additions & 14 deletions src/cpp/session/SessionModuleContext.cpp
Expand Up @@ -1074,20 +1074,18 @@ bool addTinytexToPathIfNecessary()
{
if (isPdfLatexInstalled())
return false;

FilePath binPath;

#if defined(_WIN32)
FilePath appData(core::system::getenv("APPDATA"));
binPath = appData.complete("TinyTeX\\bin\\win32");
#elif defined(__APPLE__)
binPath = resolveAliasedPath("~/Library/TinyTeX/bin/x86_64-darwin");
#else
binPath = resolveAliasedPath("~/bin");
#endif

if (binPath.childPath("pdflatex").exists())
core::system::addToSystemPath(binPath);

std::string binDir;
Error error = r::exec::RFunction(".rs.tinytexBin").call(&binDir);
if (error)
LOG_ERROR(error);

FilePath binPath = module_context::resolveAliasedPath(binDir);
if (!binPath.exists())
return false;

core::system::addToSystemPath(binPath);
return true;
}

bool isPdfLatexInstalled()
Expand Down
15 changes: 14 additions & 1 deletion src/cpp/session/modules/SessionRMarkdown.R
Expand Up @@ -462,4 +462,17 @@
FALSE
})


.rs.addFunction("tinytexBin", function()
{
if (!requireNamespace("tinytex", quietly = TRUE))
return(NULL)

# NOTE: binary directory has a single arch-specific subdir;
# rather than trying to hard-code the architecture we just
# infer it directly
root <- tinytex:::tinytex_root()
bin <- file.path(root, "bin")
subbin <- list.files(bin, full.names = TRUE)
subbin[[1]]

})

0 comments on commit cc7a5cc

Please sign in to comment.