| 335 | } |
| 336 | |
| 337 | bool TeXRenderer::enabled() { |
| 338 | auto group = Settings::group(QStringLiteral("Settings_Worksheet")); |
| 339 | QString engine = group.readEntry("LaTeXEngine", ""); |
| 340 | if (engine.isEmpty()) { |
| 341 | // empty string was found in the settings (either the settings never saved or no tex engine was available during the last save) |
| 342 | //->check whether the latex environment was installed in the meantime |
| 343 | engine = QLatin1String("xelatex"); |
| 344 | if (!executableExists(engine)) { |
| 345 | engine = QLatin1String("lualatex"); |
| 346 | if (!executableExists(engine)) { |
| 347 | engine = QLatin1String("pdflatex"); |
| 348 | if (!executableExists(engine)) |
| 349 | engine = QLatin1String("latex"); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | if (!engine.isEmpty()) { |
| 354 | // one of the tex engines was found -> automatically save it in the settings without any user action |
| 355 | group.writeEntry(QLatin1String("LaTeXEngine"), engine); |
| 356 | group.sync(); |
| 357 | } |
| 358 | } else if (!executableExists(engine)) { |
| 359 | WARN("LaTeX engine does not exist"); |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | // Tools needed to convert generated DVI files to PS and PDF |
| 364 | if (engine == QLatin1String("latex")) { |
| 365 | if (!executableExists(QLatin1String("convert"))) { |
| 366 | WARN("program \"convert\" does not exist"); |
| 367 | return false; |
| 368 | } |
| 369 | if (!executableExists(QLatin1String("dvips"))) { |
| 370 | WARN("program \"dvips\" does not exist"); |
| 371 | return false; |
| 372 | } |
| 373 | |
| 374 | #if defined(_WIN64) |
| 375 | if (!executableExists(QLatin1String("gswin64c")) && !QDir(QString::fromLocal8Bit(qgetenv("PROGRAMFILES")) + QStringLiteral("/gs")).exists() |
| 376 | && !QDir(QString::fromLocal8Bit(qgetenv("PROGRAMFILES(X86)")) + QStringLiteral("/gs")).exists()) { |
| 377 | WARN("ghostscript (64bit) does not exist"); |
| 378 | return false; |
| 379 | } |
| 380 | #elif defined(HAVE_WINDOWS) |
| 381 | if (!executableExists(QLatin1String("gswin32c")) && !QDir(QString::fromLocal8Bit(qgetenv("PROGRAMFILES")) + QStringLiteral("/gs")).exists()) { |
| 382 | WARN("ghostscript (32bit) does not exist"); |
| 383 | return false; |
| 384 | } |
| 385 | #endif |
| 386 | } |
| 387 | |
| 388 | return true; |
| 389 | } |
| 390 | |
| 391 | bool TeXRenderer::executableExists(const QString& exe) { |
| 392 | return !safeExecutableName(exe).isEmpty(); |