From d55019e9356e13967cba1bf70521f3a5ef23bea9 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Tue, 30 Jul 2019 13:13:05 -0400 Subject: alphabetization trial --- .gitignore | 3 +++ citations.tex | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mla8.tex | 35 ++++++++++++++++++++++++++++++----- sort.py | 27 +++++++++++++++++++++++++++ sort.tex | 1 + 5 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 sort.py create mode 100644 sort.tex diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7ae651 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.sort.py.swp +*.log +*.pdf diff --git a/citations.tex b/citations.tex index e69de29..12ea915 100644 --- a/citations.tex +++ b/citations.tex @@ -0,0 +1,53 @@ +\long\edef\citations{} +\long\def\newcitation#1#2{% + \long\edef\citations{{#2}%allows alphabetization by including sanitized relevant data + \hangafter=-1 \hangindent=0.5in%hanging indents must be inserted every paragraph + \citations\par #1}% +} +\def\cite#1{%the actual citation request made by users + \def\cltitle{}\def\clcontain{}%"clean" data intended for alphabetization in bibliography + \def\ifnameinline{\iffalse}\def\nameinline{\def\ifnameinline{\iftrue}}% + \def\ifnewcite{\iffalse}\def\newcite{\def\ifnewcite{\iftrue}}% + \def\ifusetitle{\iffalse}\def\usetitle{\def\ifusetitle{\iftrue}}% + \def\@last{}\def\@namedisp{}\def\name##1##2{\def\@last{##1}\def\@namedisp{\ifx\@title\empty ##2.\fi}}%takes a last name and how names ought display, allowing multiple authors + \def\@title{}\def\title##1{\def\@title{``##1.''}\def\cltitle{##1}}%individual source like chapter or webpage + \def\@contain{}\def\contain##1{\def\@contain{ {\twelveit ##1}\ifx\@title\empty .\else, by \@namedisp \comma \fi}\def\clcontain{##1}}%container (book contains chapter) + \def\@contrib{}\def\contrib##1{\def\@contrib{ ##1\comma}}%other contributors with roles + \def\@version{}\def\version##1{\def\@version{ ##1\comma}}%version, if notable or unique + \def\@relnums{}\def\relnums##1{\def\@relnums{ ##1\comma}}%relevant numbers like journal issue or volume number + \def\@publish{}\def\publish##1{\def\@publish{ ##1\comma}}%publisher + \def\@pubdate{}\def\pubdate##1{\def\@pubdate{ ##1\comma}}%publication date + \def\@locator{}\def\locator##1{\def\@locator{ ##1}}%page numbers or web address + \def\@pagenum{}\def\pagenum##1{\def\@pagenum{##1}}%page number, as relevant to inline citations + \countdef\commas=11\count11=0% + #1% + \ifx\@contrib\empty \else \advance \commas by 1\fi% + \ifx\@version\empty \else \advance \commas by 1\fi% + \ifx\@relnums\empty \else \advance \commas by 1\fi% + \ifx\@publish\empty \else \advance \commas by 1\fi% + \ifx\@pubdate\empty \else \advance \commas by 1\fi% + \ifx\@locator\empty \else \advance \commas by 1\fi% + \def\comma{\advance\commas by -1 \noexpand\ifnum\noexpand\commas>0 ,\noexpand\fi}% + \ifnewcite\newcitation{\@namedisp \@title \@contain \@contrib \@version \@relnums \@publish \@pubdate \@locator.}\fi{\@namedisp\cltitle\clcontain}\fi% + (\ifnameinline + \ifx\@last\empty + \@title + \else + \@last + \fi + \fi \@pagenum)% +} + +\long\def\biblio{ %generates a bibliography + \vfil \eject %prints all previous pages and starts bibliography + \line{\hfil Works Cited \hfil}% + %%Alphabetization + \immediate\openout0=sort.tex% + \immediate\write0{\citations}% + \immediate\closeout0 + \immediate\write18{python3 sort.py}%sort sort.tex alphabetically by the first group (also remove first group) + \immediate\openin0=sort.tex + \immediate\read0 to \data + \immediate\data + \immediate\closein0 +} diff --git a/mla8.tex b/mla8.tex index 2f99c76..93680df 100644 --- a/mla8.tex +++ b/mla8.tex @@ -37,7 +37,9 @@ \def\@last{} \def\last#1{\def\@last{#1}} \def\@prof{} \def\prof#1{\def\@prof{#1}} \def\@clas{} \def\clas#1{\def\@clas{#1}} -\def\@date{\the\day \threemonth{\the\month}\ \the\year} +\def\today{\the\day \threemonth{\the\month}\ \the\year} +\def\setdate#1{\def\@date{#1}} %sets \@date to user value +\def\@date{\today} %uses today's date if author doesn't choose; to choose, author should use \setdate \long\def\header{ \noindent\@name\ \@last \par @@ -61,13 +63,23 @@ \parindent=0.5in +%%citation formatting (\cite and \biblio) from relevant local file + +\input citations.tex + %%fixes @ character \catcode `\@12\relax -%%citation formatting (\cite and \biblio) from relevant local file +%%blockquotes -\input citations.tex +\long\def\blockquote#1{{ %double bracket to group + \par + \everyhbox{x} + \leftskip=1in \parindent=0.25in + \noindent#1 + \par +}} %%test stuff \numberfirstpage \spaceaftertitle @@ -75,6 +87,19 @@ \prof{Jones} \header \title{Text} -epic bruh moment - +epic bruh moment: +\blockquote{yo your mom was here last nite it was litty + +test par that should continue onto the next line like this tlike this like this like this like this like this like this like this + +but what if} +This stuff is back outside of the blockquote \cite{% + \name{McDonald and Patten Jr.}{McDonald, Douglas, and Carl Patten Jr}% + \contain{Emerging Issues on Privatized Prisons}% + \publish{Bureau of Justice Assistance}% + \pubdate{Feb. 2001}% + \locator{www.ncjrs.gov/pdffiles1/nij/grants/203968.pdf}% + \nameinline \newcite +} +\biblio \bye diff --git a/sort.py b/sort.py new file mode 100644 index 0000000..00007bc --- /dev/null +++ b/sort.py @@ -0,0 +1,27 @@ +#Intended as an auxiliary program for citations.tex to alphabetize an output file based on the first group. + +#Inputs file sort.tex, to sort as read, takes all data, and then reopens as write +f = open('sort.tex','r') +dat = f.readlines() +f.close() +f = open('sort.tex','w') + +def firstgroup(line): #handles nested brackets to return (first group data, other data) tuple. + nesting = 0 + for charind in range(len(line)): + char = line[charind] + if char == '{': + nesting += 1 + if char == '}': + nesting -= 1 + if nesting == 0: + breakchar = charind+1 + break + return (line[1:breakchar], line[breakchar:]) + +for lineind in range(len(dat)): + line = dat[lineind] + dat[lineind] = firstgroup(line) + +dat.sort(key=lambda text : [ord(char) for char in text[0]]) +f.write(''.join([line[1] for line in dat])) diff --git a/sort.tex b/sort.tex new file mode 100644 index 0000000..c93cae4 --- /dev/null +++ b/sort.tex @@ -0,0 +1 @@ +real text -- cgit