<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" >

<channel><title><![CDATA[Daniel L. Greenwald - Miscellanea]]></title><link><![CDATA[https://www.dlgreenwald.com/miscellanea]]></link><description><![CDATA[Miscellanea]]></description><pubDate>Wed, 08 Apr 2026 10:56:47 -0400</pubDate><generator>Weebly</generator><item><title><![CDATA[New LaTeX CV Template﻿]]></title><link><![CDATA[https://www.dlgreenwald.com/miscellanea/new-latex-cv-template]]></link><comments><![CDATA[https://www.dlgreenwald.com/miscellanea/new-latex-cv-template#comments]]></comments><pubDate>Sun, 27 Mar 2016 21:02:47 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://www.dlgreenwald.com/miscellanea/new-latex-cv-template</guid><description><![CDATA[I recently decided to make a new CV in LaTeX, and quickly ran into a problem: I found most existing templates, such as those found here&nbsp;or here&nbsp;to be a little too complicated for my taste. So I decided to make my own.I started by looking at some CVs online, and picked a favorite. To aid in my shameless copying of this very nice CV, I wrote a simple LaTeX template, which you can download here.The template is based on a few simple environments and commands.Environments:&nbsp;All of the f [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">I recently decided to make a new CV in LaTeX, and quickly ran into a problem: I found most existing templates, such as those found <a href="http://www.latextemplates.com/cat/curricula-vitae">here</a>&nbsp;or <a href="https://www.overleaf.com/gallery/tagged/cv/page/2#.VvfloHUrL0M">here</a>&nbsp;to be a little too complicated for my taste. So I decided to make my own.<br /><br />I started by looking at some CVs online, and picked a favorite. To aid in my shameless copying of this very nice CV, I wrote a simple LaTeX template, which you can download <a href="https://www.dlgreenwald.com/uploads/4/5/2/8/45280895/greenwald_cv.tex">here</a>.<br /><br />The template is based on a few simple environments and commands.<br /><br /><u>Environments:</u>&nbsp;All of the following environments include a section header as an argument (see \cvsec, below).<br /><br />cvfree: An unformatted section of the CV.<br /><br />cvchrono: A tabular format used for chronological entries.<br /><br />cvlist: An enumerated list. The numbering will reset every time this command is used.<br /><br />cvcontinue: An enumerated list where the numbering continues from the last enumerated list.<br /><br /><u>Commands:</u><br /><br />\cvsec{title}: A section of the CV. It automatically avoids a page break between the section header and the first entry.<br /><br />\cvitem{date}{entry}: An item for the cvchrono environment. To accommodate multiple rows for "entry" just include them with e.g. \cvitem{2016}{some entry \\ &amp; continued \\ &amp; continued further}, where the "\\ &amp;" separators take advantage of the fact that there is a tabular environment operating under the hood.<br /><br />\cvpaper{title}{abstract}: A paper title with abstract below.<br /><br /></div>]]></content:encoded></item><item><title><![CDATA[Capitalizing Titles in BibTeX﻿]]></title><link><![CDATA[https://www.dlgreenwald.com/miscellanea/capitalizing-titles-in-bibtex]]></link><comments><![CDATA[https://www.dlgreenwald.com/miscellanea/capitalizing-titles-in-bibtex#comments]]></comments><pubDate>Sun, 08 Nov 2015 01:45:41 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://www.dlgreenwald.com/miscellanea/capitalizing-titles-in-bibtex</guid><description><![CDATA[A simple little application popped up recently for some of Python's amazing regular expressions tools that I thought I would share.Like many academics, I use BibTeX to manage citations in papers, which makes adding and citing references a breeze. Even better, many web sources, including Google Scholar, automatically generate the BibTeX code for you, which you can paste directly into your .bib file. For a&nbsp;s̶h̶a̶m̶e̶l̶e̶s̶s̶ ̶p̶l̶u̶g̶ relevant example, the automatically generate [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">A simple little application popped up recently for some of Python's amazing regular expressions tools that I thought I would share.<br><br>Like many academics, I use BibTeX to manage citations in papers, which makes adding and citing references a breeze. Even better, many web sources, including Google Scholar, automatically generate the BibTeX code for you, which you can paste directly into your .bib file. For a&nbsp;s&#822;h&#822;a&#822;m&#822;e&#822;l&#822;e&#822;s&#822;s&#822; &#822;p&#822;l&#822;u&#822;g&#822; relevant example, the automatically generated BibTeX code for "Rare Shocks, Great Recessions" is:<br></div><div><div id="812395218323602717" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre class="prettyprint">@article{curdia2014rare,  title={Rare shocks, great recessions},  author={C{\'u}rdia, Vasco and Negro, Marco and Greenwald, Daniel L},  journal={Journal of Applied Econometrics},  volume={29},  number={7},  pages={1031--1052},  year={2014},  publisher={Wiley Online Library}}</pre></div></div><div class="paragraph" style="text-align:left;"><br>&#8203;Everything is perfect except for one tiny thing...the title isn't capitalized! I prefer "Rare Shocks, Great Recessions."<br><br>Basically all automatically generated BibTeX entries don't capitalize, so if I wanted to change this for every title in my bibliography it would mean a ton of manual editing. Instead, I wrote a little Python script that takes care of this using regular expressions and the <a href="https://pypi.python.org/pypi/titlecase">titlecase</a> module. Enjoy!</div><div><div id="869047660595967995" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre class="prettyprint">"""This script replaces lowercase titles in BibTeX entries with titlecasee.g., 'The greatest title of the all time' to 'The Greatest Title of All Time'."""import refrom titlecase import titlecase# Set path and name of bib filesdirectory = '/path/to/my/file/'my_file = 'my_bibfile.bib'new_file = 'new_bibfile.bib' # in case you don't want to overwrite# Match title or journal segment allowing for whitespace (UPDATED 8/12/19)pattern = re.compile(r'(\W*)(title|journal)\s*=\s*{(.*)},')# Read in old filewith open(directory + my_file, 'r') as fid:    lines = fid.readlines()# Search for title strings and replace with titlecasenewlines = []for line in lines:    # Check if line contains title    match_obj = pattern.match(line)    if match_obj is not None:        # Need to "escape" any special chars to avoid misinterpreting them in the regular expression.        oldtitle = re.escape(match_obj.group(3))        # Apply titlecase to get the correct title.        newtitle = titlecase(match_obj.group(3))        # Replace and add to list        p_title = re.compile(oldtitle)        newline = p_title.sub(newtitle, line)        newlines.append(newline)    else:        # If not title, add as is.        newlines.append(line)# Print output to new filewith open (directory + new_file, 'w') as fid:    fid.writelines(newlines)</pre></div></div>]]></content:encoded></item><item><title><![CDATA[Ordering Equations with NetworkX]]></title><link><![CDATA[https://www.dlgreenwald.com/miscellanea/ordering-equations-with-networkx]]></link><comments><![CDATA[https://www.dlgreenwald.com/miscellanea/ordering-equations-with-networkx#comments]]></comments><pubDate>Sun, 06 Sep 2015 16:37:45 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://www.dlgreenwald.com/miscellanea/ordering-equations-with-networkx</guid><description><![CDATA[I recently came across an interesting problem. I needed to set values for a bunch of variables, call them $x_1, \ldots, x_n$, and each one had a known rule of the form:$$ x_i = f(x_{i_1}, ..., x_{i_{k}}) $$so that each variable needed be initialized as a function of some set of other variables (possibly empty). This type of problem is familiar to many economists, (e.g., setting initial values in the popular macroeconomics software Dynare), but likely occurs in many other scientific computing app [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:justify;">I recently came across an interesting problem. I needed to set values for a bunch of variables, call them $x_1, \ldots, x_n$, and each one had a known rule of the form:<br><br>$$ x_i = f(x_{i_1}, ..., x_{i_{k}}) $$<br><br>so that each variable needed be initialized as a function of some set of other variables (possibly empty). This type of problem is familiar to many economists, (e.g., setting initial values in the popular macroeconomics software <a href="http://www.dynare.org/">Dynare</a>), but likely occurs in many other scientific computing applications as well.&nbsp;<br><br>As anyone who has tackled this situation knows, the tricky part is ordering the rules so that each $x_i$ is initialized after all the variables it depends on. For small problems, this can be done manually without too much trouble. As the size of the problem grows, however, the complexity of this task can easily get out of hand. For example, in my application, the dependency structure turned out to be:<br></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:left"><a><img src="https://www.dlgreenwald.com/uploads/4/5/2/8/45280895/4904910_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph" style="text-align:left;"><span style=""><br></span><br><span style="">Yikes. Doing this manually would be a nightmare. Let's automate it!</span><br><br><span style="">My approach was to create a&nbsp;</span><a href="https://en.wikipedia.org/wiki/Directed_graph" title="" style="">directed graph</a><span style="">, which is a collection of nodes combined with one-way arrows connecting those nodes. I constructed a graph with the $\{x_i\}$ as the nodes, and then added an arrow from each $x_i$ to every $x_j$ that depends on it. Once the graph is constructed, running a&nbsp;</span><a href="https://en.wikipedia.org/wiki/Topological_sorting" title="" style="">topological sort</a><span style="">&nbsp;generates a list of the variables in order so that each node is listed after all of its dependencies -- exactly what we needed.</span><br><br><span style="">To demonstrate, I'll show a simple example:</span><br></div><div><div id="145330284657787779" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre class="prettyprint">a = 2.0 * c;b = a + c;c = 5.0;</pre></div></div><div class="paragraph" style="text-align:left;"><br>In this case, the solution is to initialize $c$ first, then $a$, then $b$.&nbsp;<br><br>To implement the directed graph, I used the excellent Python package <a href="https://networkx.github.io/">NetworkX</a>. I started with a dict of (var, rule) pairs.&nbsp;For each rule, I extracted all the variable names using Python's regular expressions (<a href="https://docs.python.org/3.4/library/re.html">re</a>) module. I then constructed the graph and ran the sort. Here's the code:<br></div><div><div id="789694874783766170" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre class="prettyprint">import networkx as nximport re"""Construct regular expressions pattern to search for variable names.This will find all blocks of letters, numbers, or underscoresstarting with a letter or underscore."""pattern = re.compile('[a-zA-Z_]\w*')# Initialize the graphG = nx.DiGraph()# Example set of rulesrules = {    'a' : '2.0 * c',    'b' : 'a + c',    'c' : '5.0',}# Loop through the rulesfor var, rule in rules.items():    # Add variable to graph    G.add_node(var)    # Get list of dependencies    dependencies = re.findall(pattern, rule)    # Add edges    for dep in dependencies:        G.add_edge(dep, var)# Get sorted variable listsorted_vars = nx.topological_sort(G)# Get sorted list of rulessorted_rules = [(var, rules[var]) for var in sorted_vars]# Print resultsfor var, rule in sorted_rules:    print('{0} = {1};\n'.format(var, rule))</pre></div></div><div class="paragraph" style="text-align:left;"><br>The output is:<br></div><div><div id="184895883435945631" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre class="prettyprint">c = 5.0;a = 2.0 * c;b = a + c;</pre></div></div><div class="paragraph" style="text-align:left;"><br>just like we wanted.&nbsp;<br></div>]]></content:encoded></item><item><title><![CDATA[Pretty Printing Eigen Objects in GDB]]></title><link><![CDATA[https://www.dlgreenwald.com/miscellanea/first-post]]></link><comments><![CDATA[https://www.dlgreenwald.com/miscellanea/first-post#comments]]></comments><pubDate>Fri, 04 Sep 2015 15:23:57 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://www.dlgreenwald.com/miscellanea/first-post</guid><description><![CDATA[Eigen is a fantastic matrix and linear algebra library for C++, which I highly recommend.Since it's important to be able to see inside a matrix while debugging, Eigen has provided Python "pretty printer" scripts for debuggers. The scripts for gdb (the debugger I use), are located in eigen/debug/gdb.&nbsp;Note: package managers may not include this directory. If you don't have it, you can download a new copy of Eigen here. You don't need to replace your existing installation, just put the eigen/d [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;"><a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">Eigen</a> is a fantastic matrix and linear algebra library for C++, which I highly recommend.<br><br>Since it's important to be able to see inside a matrix while debugging, Eigen has provided Python "pretty printer" scripts for debuggers. The scripts for gdb (the debugger I use), are located in eigen/debug/gdb.&nbsp;<br><br>Note: package managers may not include this directory. If you don't have it, you can download a new copy of Eigen <a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">here</a>. You don't need to replace your existing installation, just put the eigen/debug/gdb directory somewhere and use that for the instructions below.<br><br>If you follow the directions in the comments of printers.py (in this directory), you can set up gdb so that it will print the contents of the matrix rather than some obscure sequence of pointers and iterators when you are debugging. Great!<br><br>Recently, however, I started seeing the pointers and iterators again instead of the content. I also started getting errors like:<span style=""><br></span></div><div><div id="202309533891586995" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre class="prettyprint">TypeError: 'map' object is not subscriptable</pre></div></div><div class="paragraph" style="text-align:left;"><br>This error is caused by the fact that the printers.py script is in Python 2, while my version of gdb is built in Python 3. To fix this issue, you can use the Python utility 2to3, which automatically converts Python 2 code to Python 3 code. To do this, go to the eigen/debug/gdb directory and run the shell command<br></div><div><div id="266120694592915585" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre class="prettyprint">2to3 -w printers.py</pre></div></div><div class="paragraph" style="text-align:left;"><br>You should be good to go!</div>]]></content:encoded></item></channel></rss>