NoTeX
1.0.0
A modern noteworthy LaTeX template
Toggle main menu visibility
Loading...
Searching...
No Matches
notex
src
notex
environment.cpp
1
9
10
#include "
notex/environment.hpp
"
11
12
#include "
notex/errors.hpp
"
13
#include "
notex/logging.hpp
"
14
#include "
notex/system.hpp
"
15
16
namespace
notex
{
17
18
std::string_view
to_string
(
InstallationType
type) {
19
switch
(type) {
20
case
InstallationType::NONE
:
21
return
"none"
;
22
case
InstallationType::LOCAL
:
23
return
"local"
;
24
case
InstallationType::GLOBAL
:
25
return
"global"
;
26
}
27
return
"none"
;
28
}
29
30
std::filesystem::path Environment::resolve_texmf_home() {
31
if
(
const
auto
env_value =
system::get_env
(
"TEXMFHOME"
);
32
env_value.has_value() && !env_value->empty()) {
33
PLOG_DEBUG <<
"Resolved TEXMFHOME from the environment variable: "
34
<< *env_value;
35
return
std::filesystem::path(*env_value);
36
}
37
38
PLOG_DEBUG <<
"TEXMFHOME is not set; falling back to "
39
"'kpsewhich -var-value=TEXMFHOME'."
;
40
try
{
41
const
std::string kpsewhich_output =
42
system::run_command
(
"kpsewhich -var-value=TEXMFHOME"
);
43
if
(!kpsewhich_output.empty()) {
44
PLOG_DEBUG <<
"Resolved TEXMFHOME via kpsewhich: "
45
<< kpsewhich_output;
46
return
std::filesystem::path(kpsewhich_output);
47
}
48
}
catch
(
const
NotexError& e) {
49
// kpsewhich is absent or failed; fall through to the error below,
50
// which reports both resolution paths having failed.
51
PLOG_DEBUG <<
"kpsewhich fallback failed: "
<< e.what();
52
}
53
54
PLOG_WARNING <<
"Could not resolve TEXMFHOME from either the "
55
"environment variable or kpsewhich."
;
56
throw
EnvironmentError(
57
"could not resolve TEXMFHOME: set the TEXMFHOME environment "
58
"variable, or make sure 'kpsewhich' is available on PATH."
);
59
}
60
61
Environment::Environment
(std::filesystem::path start_dir)
62
: texmf_home_(resolve_texmf_home()),
63
global_latex_dir_(texmf_home_ /
"tex"
/
"latex"
/
"notex"
),
64
global_fonts_dir_(texmf_home_ /
"fonts"
/
"truetype"
/
"notex"
),
65
local_latex_dir_(start_dir /
"settings"
),
66
local_fonts_dir_(start_dir /
"fonts"
) {
67
const
bool
local_present =
68
std::filesystem::exists(local_latex_dir_ /
"notex.cls"
);
69
const
bool
global_present =
70
std::filesystem::exists(global_latex_dir_ /
"notex.cls"
);
71
72
if
(local_present) {
73
installation_type_ =
InstallationType::LOCAL
;
74
}
else
if
(global_present) {
75
installation_type_ =
InstallationType::GLOBAL
;
76
}
else
{
77
installation_type_ =
InstallationType::NONE
;
78
}
79
PLOG_DEBUG <<
"Installation type detected: "
80
<<
to_string
(installation_type_);
81
}
82
83
}
// namespace notex
notex::Environment::Environment
Environment(std::filesystem::path start_dir=std::filesystem::current_path())
Resolves TEXMFHOME and checks start_dir for a local installation.
Definition
environment.cpp:61
environment.hpp
Environment: discovers where TeX lives and whether NoTeX is installed.
errors.hpp
Exception hierarchy and process exit codes used throughout NoTeX.
logging.hpp
Logging utility with plog initialization.
notex::system::get_env
std::optional< std::string > get_env(const std::string &name)
Reads an environment variable.
Definition
system.cpp:52
notex::system::run_command
std::string run_command(const std::string &command)
Runs command through the shell and returns everything it wrote to standard output (and standard error...
Definition
system.cpp:19
notex
Definition
assets.hpp:20
notex::InstallationType
InstallationType
Definition
environment.hpp:16
notex::InstallationType::LOCAL
@ LOCAL
A local installation exists (takes precedence over global).
Definition
environment.hpp:18
notex::InstallationType::GLOBAL
@ GLOBAL
Only a global installation exists.
Definition
environment.hpp:19
notex::InstallationType::NONE
@ NONE
Neither a local nor a global installation was found.
Definition
environment.hpp:17
notex::to_string
std::string_view to_string(InstallationType type)
Definition
environment.cpp:18
system.hpp
Process execution and environment-variable access.
Generated by
1.17.0