NoTeX 1.0.0
A modern noteworthy LaTeX template
Loading...
Searching...
No Matches
reference.cpp
1
8
9#include "notex/reference.hpp"
10
11#include <algorithm>
12
13namespace notex::reference {
14
15namespace {
16
21struct Entry {
22 std::string_view name;
23 std::vector<std::string_view> aliases;
24 std::string_view content;
25};
26
27const std::vector<Entry>& entries() {
28 static const std::vector<Entry> kEntries = {
29 {"info",
30 {},
31 "\\begin{info}[OPTIONAL_COLOR]\n WRITE_HERE\n\\end{info}\n"},
32 {"warning",
33 {},
34 "\\begin{warning}[OPTIONAL_COLOR]\n WRITE_HERE\n"
35 "\\end{warning}\n"},
36 {"note",
37 {},
38 "\\begin{note}[OPTIONAL_COLOR]\n WRITE_HERE\n\\end{note}\n"},
39 {"tip",
40 {},
41 "\\begin{tip}[OPTIONAL_COLOR]\n WRITE_HERE\n\\end{tip}\n"},
42 {"important",
43 {},
44 "\\begin{important}[OPTIONAL_COLOR]\n WRITE_HERE\n"
45 "\\end{important}\n"},
46 {"caution",
47 {},
48 "\\begin{caution}[OPTIONAL_COLOR]\n WRITE_HERE\n"
49 "\\end{caution}\n"},
50 {"cbox",
51 {"box"},
52 "\\begin{cbox}[OPTIONAL_COLOR]\n WRITE_HERE\n\\end{cbox}\n"},
53 {"ebox",
54 {"box"},
55 "\\begin{ebox}[OPTIONAL_COLOR]\n WRITE_HERE\n\\end{ebox}\n"},
56 {"example",
57 {},
58 "\\begin{example}[OPTIONAL_TITLE][OPTIONAL_LABEL]\n"
59 " WRITE_HERE\n\\end{example}\n"},
60 {"definition",
61 {},
62 "\\begin{definition}[OPTIONAL_TITLE][OPTIONAL_LABEL]\n"
63 " WRITE_HERE\n\\end{definition}\n"},
64 {"theorem",
65 {},
66 "\\begin{theorem}[OPTIONAL_TITLE][OPTIONAL_LABEL]\n"
67 " WRITE_HERE\n\\end{theorem}\n"},
68 {"corollary",
69 {},
70 "\\begin{corollary}[OPTIONAL_TITLE][OPTIONAL_LABEL]\n"
71 " WRITE_HERE\n\\end{corollary}\n"},
72 {"proposition",
73 {},
74 "\\begin{proposition}[OPTIONAL_TITLE][OPTIONAL_LABEL]\n"
75 " WRITE_HERE\n\\end{proposition}\n"},
76 {"lemma",
77 {},
78 "\\begin{lemma}[OPTIONAL_TITLE][OPTIONAL_LABEL]\n"
79 " WRITE_HERE\n\\end{lemma}\n"},
80 {"code",
81 {},
82 "\\begin{code}[caption = OPTIONAL_CAPTION, label = OPTIONAL_LABEL]"
83 "{LANGUAGE}\n WRITE_HERE\n\\end{code}\n"},
84 {"python",
85 {},
86 "\\begin{python}[caption = OPTIONAL_CAPTION, label = OPTIONAL_LABEL]"
87 "\n WRITE_HERE\n\\end{python}\n"},
88 {"cpp",
89 {},
90 "\\begin{cpp}[caption = OPTIONAL_CAPTION, label = OPTIONAL_LABEL]"
91 "\n WRITE_HERE\n\\end{cpp}\n"},
92 {"bash",
93 {},
94 "\\begin{bash}[caption = OPTIONAL_CAPTION, label = OPTIONAL_LABEL]"
95 "\n WRITE_HERE\n\\end{bash}\n"},
96 {"pseudocode",
97 {},
98 "\\begin{pseudocode}[caption = OPTIONAL_CAPTION, "
99 "label = OPTIONAL_LABEL]\n WRITE_HERE\n\\end{pseudocode}\n"},
100 {"cc", {}, "\\cc{WRITE_HERE}\n"},
101 {"inline", {}, "\\inline[LANGUAGE]{WRITE_HERE}\n"},
102 };
103 return kEntries;
104}
105
106} // namespace
107
108const std::vector<Snippet>& all_snippets() {
109 static const std::vector<Snippet> kSnippets = [] {
110 std::vector<Snippet> snippets;
111 for (const Entry& entry : entries()) {
112 snippets.push_back(Snippet{entry.name, entry.content});
113 }
114 return snippets;
115 }();
116 return kSnippets;
117}
118
119std::vector<std::string_view> snippet_names() {
120 std::vector<std::string_view> names;
121 for (const Entry& entry : entries()) {
122 names.push_back(entry.name);
123 for (const std::string_view alias : entry.aliases) {
124 names.push_back(alias);
125 }
126 }
127 std::sort(names.begin(), names.end());
128 names.erase(std::unique(names.begin(), names.end()), names.end());
129 return names;
130}
131
132std::vector<Snippet> find_snippets(std::string_view name) {
133 std::vector<Snippet> matches;
134 for (const Entry& entry : entries()) {
135 const bool is_match =
136 entry.name == name ||
137 std::find(entry.aliases.begin(), entry.aliases.end(), name) !=
138 entry.aliases.end();
139 if (is_match) { matches.push_back(Snippet{entry.name, entry.content}); }
140 }
141 return matches;
142}
143
144} // namespace notex::reference
std::vector< std::string_view > snippet_names()
std::vector< Snippet > find_snippets(std::string_view name)
Looks up every snippet registered under name, whether as its canonical name or as an alias.
const std::vector< Snippet > & all_snippets()
reference: the table of ready-to-paste snippets served by notex get.
One ready-to-paste snippet served by notex get.
Definition reference.hpp:15