- l have a fle to include all fles, like
A.typwill includeA.1.typ,A.2.typ, andA.1.typwill includeA.1/A.2.1.typ,A.1/A.2.2.typ - the fles may link to each other too,
A.2/A.2.1.typwill includeA.1/A.1.1.typ. To slove this problem, l think the only way is to includeA.1/A.1.1.typin A.2/A.2.1.typ` - Make in
A.typ, the order of the files is alwaysA.1.typ,A.1/A.1.1.typ,A.2.typ,A.2.1.typ. InA.2.typthe order isA.2/A.2.1.typ,A.1/A.1.1.typ(An order can contrl by myself, and files that would not otherwise be included but are linked to will be included last)
In this example, the A.typ will include A.2/A.2.1.typ twice, and two same lables.
Now i try to use this code to do it(Don’t mind changing it, I don’t hink it works well):
// Check is a file has been included
#let check_included(label) = {query(label) != ()}
#let check_link(label, description) = {
if check_included(label) {
// check lable
link(label, description)
} else [
#description
]
}
#let check_path(path) = {
// Don't care it
let path_list = path.split("/")
let output=(path_list.at(0), )
for i in range(1, path_list.len()) {
if path_list.at(i) == ".."{
let temp = output.pop()
} else if path_list.at(i) == "."{
} else {
output.push(path_list.at(i))
}
}
output.join("/")
}
#let creat_link(file: "", description: "", label_in: "", need_include: ("", ), include_list: ("", ), root: "") = {
// the function I use to creat link(Maybe it can be deleted)
if file == "" and label_in == ""{
panic("No file, No lable. What do you want to do?")
}
let real_path = check_path(root + file)
if real_path in include_list {
// include_list = move_item(include_list, real_path)
} else {
need_include = ((real_path, ) + need_include)
}
let output = context {check_link(label(real_path), description)}
if label_in != "" {
output = context {check_link(label(label_in), description)}
}
if file == "" {
output
} else {
(output, need_include)
}
}
#let include_item(include_list) = {
// I want to use check_include here to make sure there is no document included twice.
for i in include_list [
#if i != "" [
#[]#label(i)
#include i
]
]
}
#let append_include(include_list, doc) = [
// append the files are included
#doc
#include_item(include_list)
]