TeX - LaTeX Asked by Bhargav Rajyaguru on July 20, 2021
I am writing my thesis and I want to insert month and year of some past events at lot of places! How to do that? Can anyone suggest me a simplest way to do it? I am very much beginner in LaTeX. And also please forgive me for my English.
I have these events listed in a text file. e.g. Superconductivity was discovered in April, 1991 by Heike Kamerlingh Onnes.
I am just expecting output formatted like
April, 1991
You could simply define a macro which stores the relevant data, for example, you could use newcommandquestionDay{Monday}
to store the day on which you asked this question. Then you could use questionDay
in your paragraph wherever you want to refer to this day. However, keep in mind that spaces are ignored after macro names, so if you want a space following questionDay
you could use questionDay{}
instead.
Another approach could be to store the data in some data structure and retrieve that. The following implements such a data structure that you can initialize giving a macro name and a list of key=value
pairs which store properties for this macro name. When you then use the macro it'll accept one argument, being one of the properties stored earlier, and it'll typeset that property's value.
This example shows both methods:
documentclass[]{article}
% basic approach
newcommandquestionday{9th}
newcommandquestionDay{Monday}
newcommandquestionyear{2020}
newcommandquestionmonth{November}
usepackage{xparse}
% property list based approach
ExplSyntaxOn
msg_new:nnn { Bhargav } { already-defined }
{ #1 ~ `#2' ~ is ~ already ~ defined. }
msg_new:nnn { Bhargav } { unknown~property }
{ The ~ property ~ `#2' ~ isn't ~ found ~ for ~ `#1'. }
tl_new:N l_Bhargav_tmp_tl
NewDocumentCommand newevent { m m }
{
prop_if_exist:cTF { c_Bhargav_event_ token_to_str:N #1 _prop }
{
msg_error:nnxx { Bhargav } { already-defined }
{ The ~ property ~ list ~ for } { token_to_str:N #1 }
}
{
NewDocumentCommand #1 { m }
{
group_begin:
prop_get:cnN
{ c_Bhargav_event_ token_to_str:N #1 _prop }
{ ##1 }
l_Bhargav_tmp_tl
quark_if_no_value:NTF l_Bhargav_tmp_tl
{
msg_error:nnxx { Bhargav } { unknown~property }
{ token_to_str:N #1 } { exp_not:n {##1} }
}
{ l_Bhargav_tmp_tl }
group_end:
}
prop_const_from_keyval:cn
{ c_Bhargav_event_ token_to_str:N #1 _prop }
{#2}
}
}
ExplSyntaxOff
% defining a new property list
neweventdeathfreddie
{%
year=1991,
month=11,
day=24,
Month=November,
}
begin{document}
Bhargav Rajyaguru asked a question on questionDay{} the questionday{} of
questionmonth, questionyear.
It was very sad that Freddie Mercury died on
deathfreddie{year}-deathfreddie{month}-deathfreddie{day}. That was the
saddest deathfreddie{Month} in deathfreddie{year}.
end{document}
Correct answer by Skillmon on July 20, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP