How to add reference list and citations in mlreportgen?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Is there a way to easily add references to a report with mlreportgen when you're working with a Word template? Regular reference list and citations in this format:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Volutpat odio facilisis mauris sit [1]. Arcu non odio euismod lacinia at quis risus. Turpis massa sed elementum tempus egestas sed [2].
...
References:
- Last name, First name. "Massa enim nec dui nunc mattis enim." 2021.
- ...
- ..."
Currently my solution is this:
ref1 = Paragraph("Last name, First name. 'Massa enim nec dui nunc mattis enim.' 2021.");
append(ref1, LinkTarget("1"));
cite1 = InternalLink("1", "[1].");
citeText = Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " + ...
"Penatibus et magnis dis parturient montes nascetur ridiculus mus. Aliquam ut porttitor leo a diam sollicitudin tempor. Amet massa vitae tortor condimentum lacinia quis vel eros. " + ...
"Quis lectus nulla at volutpat diam ut venenatis tellus ");
...
p = Paragraph();
p.WhiteSpace = "preserve";
append(p, citeText);
append(p, cite1);
append(D, p); %D = Document
...
references = OrderedList([ref1, ref2, ref3]);
references.StyleName = 'RefList';
append(D, references);
This is a rather annoying way of doing it. So I'm wondering if there is an easier way.
0 Kommentare
Antworten (1)
Sameer
am 22 Mai 2024
Hi Elsa
From my understanding, you want to find an efficient way to add references and citations into a report generated with MATLAB's “mlreportgen”, particularly when working within a Word template.
The mlreportgen does not offer a built-in feature specifically for citations and references management as similar to some word processors. A more systematic method for managing citations and references can simplify the process. This involves establishing a database or a structured list of references and then utilizing functions to automatically generate citations and the reference list from this database.
Create a Reference Database
A structured array or a table can serve as a simple yet effective reference database, containing all necessary details for each reference.
references = struct(...
'id', {'1', '2'}, ...
'author', {'Last name, First name', 'Another Last, Another First'}, ...
'title', {'Massa enim nec dui nunc mattis enim', 'Another title'}, ...
'year', {'2021', '2022'} ...
);
Create Helper Functions
Functions can automate the creation of citations and the reference list. For instance:
function link = createCitation(refDB, id)
% Find the reference by ID
ref = refDB(strcmp({refDB.id}, id));
if isempty(ref)
error('Reference not found');
end
% Create the citation link
link = InternalLink(id, sprintf("[%s]", id));
end
function list = createReferenceList(refDB)
list = OrderedList();
list.StyleName = 'RefList';
for i = 1:length(refDB)
ref = refDB(i);
text = sprintf("%s, %s. '%s.' %s.", ref.author, ref.title, ref.year);
item = Paragraph(text);
append(item, LinkTarget(ref.id));
append(list, item);
end
end
Use the Functions in Your Document
% Assuming D is the document object
p = Paragraph();
p.WhiteSpace = "preserve";
% Create and append citation
cite1 = createCitation(references, '1');
append(p, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
append(p, cite1);
append(D, p);
% At the end, append the reference list
refList = createReferenceList(references);
append(D, refList);
Please refer to the below link for more information:
I hope this helps!
Sameer
0 Kommentare
Siehe auch
Kategorien
Mehr zu Templates finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!