use of org.rstudio.core.client.tex.TexMagicComment in project rstudio by rstudio.
the class TextEditingTargetCompilePdfHelper method checkCompilers.
public void checkCompilers(final WarningBarDisplay display, TextFileType fileType) {
// for all tex files we need to parse magic comments and validate
// any explict latex proram directive
ArrayList<TexMagicComment> magicComments = null;
if (fileType.canCompilePDF()) {
magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
String latexProgramDirective = detectLatexProgramDirective(magicComments);
if (latexProgramDirective != null) {
if (latexProgramRegistry_.findTypeIgnoreCase(latexProgramDirective) == null) {
// show warning and bail
display.showWarningBar("Unknown LaTeX program type '" + latexProgramDirective + "' specified (valid types are " + latexProgramRegistry_.getPrintableTypeNames() + ")");
return;
}
}
}
// for Rnw we first determine the RnwWeave type
RnwWeave rnwWeave = null;
RnwWeaveDirective rnwWeaveDirective = null;
if (fileType.isRnw()) {
rnwWeaveDirective = detectRnwWeaveDirective(magicComments);
if (rnwWeaveDirective != null) {
rnwWeave = rnwWeaveDirective.getRnwWeave();
if (rnwWeave == null) {
// show warning and bail
display.showWarningBar("Unknown Rnw weave method '" + rnwWeaveDirective.getName() + "' specified (valid types are " + rnwWeaveRegistry_.getPrintableTypeNames() + ")");
return;
}
} else {
rnwWeave = rnwWeaveRegistry_.findTypeIgnoreCase(prefs_.defaultSweaveEngine().getValue());
}
}
final SessionInfo sessionInfo = session_.getSessionInfo();
TexCapabilities texCap = sessionInfo.getTexCapabilities();
final boolean checkForTeX = fileType.canCompilePDF() && !texCap.isTexInstalled();
final boolean checkForRnwWeave = (rnwWeave != null) && !texCap.isRnwWeaveAvailable(rnwWeave);
if (checkForTeX || checkForRnwWeave) {
// alias variables to finals
final boolean hasRnwWeaveDirective = rnwWeaveDirective != null;
final RnwWeave fRnwWeave = rnwWeave;
server_.getTexCapabilities(new ServerRequestCallback<TexCapabilities>() {
@Override
public void onResponseReceived(TexCapabilities response) {
if (checkForTeX && !response.isTexInstalled()) {
String warning;
if (Desktop.isDesktop())
warning = "No TeX installation detected. Please install " + "TeX before compiling.";
else
warning = "This server does not have TeX installed. You " + "may not be able to compile.";
display.showWarningBar(warning);
} else if (checkForRnwWeave && !response.isRnwWeaveAvailable(fRnwWeave)) {
String forContext = "";
if (hasRnwWeaveDirective)
forContext = "this file";
else if (sessionInfo.getActiveProjectFile() != null)
forContext = "Rnw files for this project";
else
forContext = "Rnw files";
display.showWarningBar(fRnwWeave.getName() + " is configured to weave " + forContext + " " + "however the " + fRnwWeave.getPackageName() + " package is not installed.");
} else {
display.hideWarningBar();
}
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
} else {
display.hideWarningBar();
}
}
use of org.rstudio.core.client.tex.TexMagicComment in project rstudio by rstudio.
the class TextEditingTargetCompilePdfHelper method getActiveRnwWeave.
// get the currently active rnw weave method -- note this can return
// null in the case that there is an embedded directive which is invalid
public RnwWeave getActiveRnwWeave() {
if (docDisplay_.getFileType().canKnitToHTML())
return rnwWeaveRegistry_.findTypeIgnoreCase("knitr");
RnwWeave weave = null;
ArrayList<TexMagicComment> magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
RnwWeaveDirective rnwWeaveDirective = detectRnwWeaveDirective(magicComments);
if (rnwWeaveDirective != null) {
weave = rnwWeaveDirective.getRnwWeave();
} else {
weave = rnwWeaveRegistry_.findTypeIgnoreCase(prefs_.defaultSweaveEngine().getValue());
}
// look for the 'driver' directive and don't inject
// concocordance if there is a custom driver
String driver = detectRnwDriverDirective(magicComments);
if (driver != null)
return RnwWeave.withNoConcordance(weave);
else
return weave;
}
use of org.rstudio.core.client.tex.TexMagicComment in project rstudio by rstudio.
the class TextEditingTargetCompilePdfHelper method getTargetFile.
public FileSystemItem getTargetFile(FileSystemItem editorFile) {
ArrayList<TexMagicComment> magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
String root = StringUtil.notNull(detectRootDirective(magicComments));
if (root.length() > 0) {
return FileSystemItem.createFile(editorFile.getParentPath().completePath(root));
} else {
String rootPref = prefs_.rootDocument().getValue();
if (rootPref.length() > 0) {
FileSystemItem projDir = session_.getSessionInfo().getActiveProjectDir();
if (projDir != null)
return FileSystemItem.createFile(projDir.completePath(rootPref));
else
return editorFile;
} else {
return editorFile;
}
}
}
Aggregations