citation-style-language/styles — pull request #1085 by rmzelle (2014-08-28 02:00:25+00:00)
Title: Delete unused macros (except for CMoS styles)

@adam3smith, @aurimasv (since you asked about it), can you give this a quick lookover? The only issue I see is some left-over XML comments above the deleted macros. I think it should be safe to make these deletions. People can always restore individual macros if they lost some CSL code they later want to reuse.

I identified all macros (https://gist.github.com/rmzelle/2d48d8af04bef4891be9) that weren't called by cs:text or cs:key using the Schematron schema at https://gist.github.com/rmzelle/cf3b5e8b4883ff524821, and removed them with lxml. I skipped all the CMoS styles on @adam3smith's request. The changes validate against the Travis tests.

I should note that ``, which returns the macro name, is a feature of ISO Schematron. Jing currently only supports the older Schematron 1.5, so I switched to using [Probatron-HP](http://www.probatron.org/probatronhp.html) (which unfortunately doesn't seem able to validate more than one style at a time), using a modified style-qc.sh:

```
for f in ${pathCSLStyles}/*.csl
do
{ echo $f; java -jar ../probatron/probatron-2.jar ../probatron/csl.sch $f; } >> ../probatron/output.txt
done
```

and some modifications made to csl-reindenting-and-info-reordering.py to remove the macros:

```
with open('missing-macros.csv') as f:
content = f.readlines()

unusedMacros = []
affectedStyles = []

for line in content:
unusedMacros.append(line.strip().split(",")[0])
affectedStyles.append(line.strip().split(",")[1])
```

```
for style in styles:

head, tail = os.path.split(style)
...
if tail in affectedStyles:
unusedMacro = unusedMacros[affectedStyles.index(tail)]
unusedMacroElement = styleElement.find('.//{http://purl.org/net/xbiblio/csl}macro[@name="' + unusedMacro +'"]')
unusedMacroElement.getparent().remove(unusedMacroElement)
```