summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/scikgtex/scikgtex.sty
blob: 6e605e6a66b90e8802fc2e57e6e8307a6f2b6792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
%% ----------------------------------------------------------------
%% scikgtex --- Scientific Knowledge Graph TeX (SciKgTeX) is a 
%% LuaLaTeX package which makes it possible to annotate specific
%% research contributions in scientific documents. SciKGTeX will 
%% enrich the document by adding marked contributions to PDF
%% metadata in a structured XMP format which can be picked up by 
%% Search Engines and Knowledge Graphs.
%% More information on how to use the package can be found here: 
%% https://github.com/Christof93/SciKGTeX#readme
%%
%% Author: Christof Bless
%% E-mail: christofbless@gmail.com
%% Released under the MIT License 
%% See https://opensource.org/licenses/MIT
%% ----------------------------------------------------------------
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{scikgtex}[2022/11/13 v2.1.1]
%
\def\useignorespacesandallpars#1\ignorespaces\fi{%
#1\fi\ignorespacesandallpars}
%
\makeatletter
\def\ignorespacesandallpars{%
  \@ifnextchar\par
    {\expandafter\ignorespacesandallpars\@gobble}%
    {}%
}
\makeatother
%
\RequirePackage{suffix}
%% init variable which checks if hyperref is loaded.
\newcommand{\hyperrefloaded}{null}%
%
\errorcontextlines=5
%
\directlua {%
  SciKGTeX = require('scikgtex')%
  CONFORM_TO_PDFA = false%
}
\DeclareOption{compatibility}{
  \directlua {% 
    CONFORM_TO_PDFA = true%
  }
}
\ProcessOptions\relax

\newcommand{\addmetaproperty}[2][]{%
  \directlua{%
    local new_property = "\luaescapestring{\unexpanded{#2}}"%
    local ns = "\luaescapestring{\unexpanded{#1}}"%
    SciKGTeX:add_property(new_property, ns)%
  }%
  \ignorespaces
}%

\newcommand{\newpropertycommand}[2][]{%
  \directlua{%
    local new_property = "\luaescapestring{\unexpanded{#2}}"%
    local ns = "\luaescapestring{\unexpanded{#1}}"%
    SciKGTeX:make_new_command(new_property, ns)%
  }%
  \ignorespaces
}%

\newcommand{\metatitle}[2][]{%
  \directlua{%
    local value = "\luaescapestring{\unexpanded{#2}}"%
    SciKGTeX.XMP:set_title(value)%
  }%
  #2%
}%

\WithSuffix\newcommand\metatitle*[2][]{%
  \directlua{%
    local value = "\luaescapestring{\unexpanded{#2}}"%
    SciKGTeX.XMP:set_title(value)%
  }%
  \ignorespaces
}%

\newcommand{\metaauthor}[2][]{%
  \directlua{%
    local value = "\luaescapestring{\unexpanded{#2}}"%
    SciKGTeX.XMP:add_author(value)%
  }%
  #2%
}%

\WithSuffix\newcommand\metaauthor*[2][]{%
  \directlua{%
    local value = "\luaescapestring{\unexpanded{#2}}"%
    SciKGTeX.XMP:add_author(value)%
  }%
  \ignorespaces
}%

\newcommand{\researchfield}[2][]{%
  \directlua{%
    local value = "\luaescapestring{\unexpanded{#2}}"%
    SciKGTeX.XMP:set_researchfield(value)%
  }%
  #2%
}%

\WithSuffix\newcommand\researchfield*[2][]{%
  \directlua{%
    local value = "\luaescapestring{\unexpanded{#2}}"%
    SciKGTeX.XMP:set_researchfield(value)%
  }%
  \ignorespaces
}%
%
\newcommand{\uri}[2]{%
  \ifcsname href\endcsname%
    \renewcommand{\hyperrefloaded}{true}%
  \else%
    \renewcommand{\hyperrefloaded}{false}%
  \fi%
%
  \directlua{%
    local label = "\luaescapestring{\unexpanded{#2}}"%
    local uri = "\luaescapestring{\unexpanded{#1}}"%
    SciKGTeX:print_entity(uri, label, \hyperrefloaded)%
  }%
}%

\newcommand{\contribution}[3][]{%
  \directlua{%
    local contrib_n = "\luaescapestring{\unexpanded{#1}}"%
    local property = "\luaescapestring{\unexpanded{#2}}"%
    local value = "\luaescapestring{\unexpanded{#3}}"%
    SciKGTeX.XMP:add_annotation(contrib_n, property, value, 'annotation-id')%
  }%
  #3%
}%

\WithSuffix\newcommand\contribution*[3][]{%
  \directlua{%
    local contrib_n = "\luaescapestring{\unexpanded{#1}}"%
    local property = "\luaescapestring{\unexpanded{#2}}"%
    local value = "\luaescapestring{\unexpanded{#3}}"%
    SciKGTeX.XMP:add_annotation(contrib_n, property, value, 'annotation-id')%
  }%
  \ignorespaces
}%

\newpropertycommand{researchproblem}
\newpropertycommand{result}
\newpropertycommand{method}
\newpropertycommand{objective}
\newpropertycommand{conclusion}
 
%% Copyright (C) 2022 by Christof Bless <christofbless@gmail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the MIT License.
%% 
%% This work consists of the file scikgtex.sty
%% and the lua file               scikgtex.lua.
%% 
%%
%% End of file `scikgtex.sty'.