Custom directives

| categories: emacs, org-mode | tags:

You can define custom special blocks in org-mode. Here is an example of creating attention and note directives. Note you need to specify the styles and environments in the header like this:

#+HTML_HEAD_EXTRA:  <style>.attention {font-size: 30px; text-indent: 50px; color: red; background-color:HotPink;}</style>
#+HTML_HEAD_EXTRA:  <style>.note {font-size: 30px; text-indent: 50px; background-color:LightSkyBlue;}</style>

#+LATEX_HEADER: \usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
#+LATEX_HEADER: \newenvironment{attention}{\color{red}}{\ignorespacesafterend}
#+LATEX_HEADER: \newenvironment{note}{\itshape}{\ignorespacesafterend}

That allows you to define different looks for exporting to html and LaTeX. For the blog post, I put the style in the body of the html.

Here is the markup for an attention block.

#+BEGIN_ATTENTION
Pay attention to this text!
#+END_ATTENTION

Renders like this:

Pay attention to this text!

A note is defined as:

#+begin_note
this is a note
#+end_note

and it renders like this:

this is a note.

I am not sure if it is possible to add arguments, e.g. via attributes. Anyway, this may enable some flexibility in adding content that may be rendered in html and LaTeX in org-mode. There is a function (org-html-special-block and org-latex-special-block) that does the rendering, and it has an info plist that probably has the information. It does not appear you can pass arguments in though. That would require a filter that redefines the rendering.

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter

Automating Adobe Acrobat Pro with python

| categories: pdf, automation | tags:

Table of Contents

I have a need to automate Adobe Pro for a couple of applications:

  1. I could use Adobe Pro to automatically add rubric pages to assignments before grading them. The rubric has embedded javascript that stores the grade inside the pdf file.
  2. I could use Adobe Pro to extract information, e.g. grades, stored in a set of PDF files for analysis.

I came across this script to automate Adobe Pro using python and OLE automation. Two other useful references are:

  1. http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/iac_api_reference.pdf
  2. http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/iac_developer_guide.pdf

In this post, we look at some simple code to get data out of a pdf. We start with just opening a PDF file.

import os
from win32com.client.dynamic import Dispatch
src = os.path.abspath('writing-exams-in-orgmode.pdf')

app = Dispatch("AcroExch.AVDoc")

app.Open(src, src)

app.Close(-1)  # do not save on close

Opening and closing a file is not that useful. Here, we can get some information out of the file. The pdf we looked at above has a custom property PTEX.Fullbanner from pdflatex. We can extract it like this.

import os
from win32com.client.dynamic import Dispatch
src = os.path.abspath('writing-exams-in-orgmode.pdf')

app = Dispatch("AcroExch.AVDoc")

app.Open(src, src)
pddoc = app.GetPDDoc()
print pddoc.GetInfo('PTEX.Fullbanner')

print pddoc.GetNumPages()
app.Close(-1)  # do not save on close
This is MiKTeX-pdfTeX 2.9.4535 (1.40.13)
5

Finally, let us try inserting pages. I have a rubric file that I want to insert at the end of the

writing-exams-in-orgmode.pdf
above. We will open both documents, insert the rubric, and save the result as a new file.

import os
from win32com.client.dynamic import Dispatch
src = os.path.abspath('../../CMU/classes/06-625/rubric/rubric.pdf')
src2 = os.path.abspath('writing-exams-in-orgmode.pdf')

# It seems I need two of these
avdoc1 = Dispatch("AcroExch.AVDoc")
avdoc2 = Dispatch("AcroExch.AVDoc")

# this is the rubric
avdoc1.Open(src, src)
pddoc1 = avdoc1.GetPDDoc()
N1 = pddoc1.GetNumPages()

# this is the other doc
avdoc2.Open(src2, src2)
pddoc2 = avdoc2.GetPDDoc()
N2 = pddoc2.GetNumPages()

# Insert rubric after last page of the other doc. pages start at 0
pddoc2.InsertPages(N2 - 1, pddoc1, 0, N1, 0)

# save as a new file. 1 means full save at absolute path provided.
pddoc2.Save(1, os.path.abspath('./woohoo.pdf'))

# close files.
avdoc1.Close(-1)
avdoc2.Close(-1)

Here is our result: woohoo.pdf . I went ahead and gave myself an A ;).

1 Summary

It looks like I can replace the dependence of my box-course code on all the python-based pdf libraries (which are not fully functional, and do not work on all pdfs), and on pdftk, with this automation approach of Adobe Pro. It is unfortunate that it is not a free program, but i would expect it to work on all PDF files, and it provides features like combining PDFs with their javascript, that no other PDF package has. I have tried other PDF programs to combine the rubric and assignment page, but they all lose the javascript. With this method, I could keep a set of enriched rubric files for different types of assignments, and add them to assignments as part of the assessment process.

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter

New PhD students join the Kitchin Research Group

| categories: news | tags:

Three new PhD students have joined the Kitchin Research Group! We are pleased to welcome Mehak Chawla, Qingqi (Victor) Fan, and John Michael (co-advised by Professor Paul Sides) to the group.

Mehak joins us from The Ohio State University. She will be using density functional theory to model metal alloy and oxide surface reactivity.

John completed his B.S. in Chemical Engineering at Miami University (OH). He will be using the imaging ammeter to screen electrocatalysts. He will be co-advised by Dr. Sides.

Victor joins us from the University of Tulsa. He will be studying oxygen evolution electrocatalysis on transition metal oxides.

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter

New publication in Topics in Catalysis

| categories: news | tags:

:END:

Simulating Temperature Programmed Desorption of Oxygen on Pt(111) Using DFT Derived Coverage Dependent Desorption Barriers Spencer D. Miller, Vladimir V. Pushkarev, Andrew J. Gellman, John R. Kitchin http://link.springer.com/article/10.1007/s11244-013-0166-3 Abstract The dissociative adsorption energy of oxygen on Pt(111) is known to be coverage dependent. Simple Redhead analysis of temperature programmed desorption (TPD) experiments that assumes a coverage independent desorption barrier can lead to errors in estimated properties such as desorption barriers and adsorption energies. A simple correction is to assume a linear coverage dependence of the desorption barrier, but there is usually no formal justification given for that functional form. More advanced TPD analysis methods that are suitable for determining coverage dependent adsorption parameters are limited by their need for large amounts of high quality, low noise data. We present a method to estimate the functional form of the coverage dependent desorption barrier from density functional theory calculations for use in analysis of TPD spectra. Density functional theory was employed to calculate the coverage dependence of the adsorption energy. Simulated TPD spectra were then produced by empirically scaling the DFT based adsorption energies utilizing the Bronstead-Evans-Polyani relationship between adsorption energies and desorption barriers. The resulting simulated spectra show better agreement with the experimental spectra than spectra predicted using barriers that are either coverage-independent or simply linearly dependent on coverage. The empirically derived scaling of the desorption barriers for Pt(111) is shown to be useful in predicting the low coverage desorption barriers for oxygen desorption from other metal surfaces, which showed reasonable agreement with the reported experimental values for those other metals. The supporting information file is especially interesting because it has nearly all of the data files used in the paper embedded in it!

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter

New publication in Catalysis Communications

| categories: news | tags:

Relating the Electronic Structure and Reactivity of the 3d Transition Metal Monoxide Surfaces

Zhongnan Xu, and John R. Kitchin

We performed a series of density functional theory calculations of dissociative oxygen adsorption on fcc metals and their corresponding rocksalt monoxides to elucidate the relationship between the oxide electronic structure and its corresponding reactivity. We decomposed the dissociative adsorption energy of oxygen on an oxide surface into a sum of the adsorption energy on the metal and a change in adsorption energy caused by both expanding and oxidizing the lattice. We were able to identify the key features of the electronic structure that explains the trends in adsorption energies on 3d transition metal monoxide surfaces.

https://doi.org/10.1016/j.catcom.2013.10.028

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

Discuss on Twitter
« Previous Page -- Next Page »