# Publishing in WordPress with emacs and org2blog

This is my first post using emacs, org2blog and wordpress. I gotta say that this will save a lot of time and make my posts a way more time-efficient. If by any change I become more active in this blog, it is because of this facility. I am going to explain how to use such functionality for mac users. I will assume that you already know how to use emacs and og-mode.

I am using Mac with Aquamacs 3.1a GNU Emacs 24.4.1, org2blog downloaded at Nov-6-2014.

The process is the same for non-mac users though. The instructions about setting org2blog can also be found here. The additional instructions about setting alias, code blocks, images and aquations in yout post from emacs I am adding by my own up to such instructions about using org2blog.

org2blog is a package that allows you to publish you posts direct from your buffer. You just have to download the package and copy the folder in your user/username.emacs.el or whatever it is your .emacs.el folder.

On Mac, the easiest way is to open the terminal and to navigate to the .emacs.el folder. Once in that folder, just type

git clone http://github.com/punchagan/org2blog.git


and you will be downloading automatically the package into to correct folder. (You can also downlaod the package manually here).

You will have to install two more packages that org2blog depends on. They are xml-rpc (available here) and metaweblog.el (available here). To download metaweblog.el you can do the same procedure you did to download org2blog. In the right folder (user/username.emacs.el) on you terminal, just type

git clone http://github.com/punchagan/metaweblog.git


In the case of the file xml-rpc, just put it in a file you want. I strongly recomend the org2blog folder of .emacs.el folder.

An alternative way is, inside the buffer:

M-x package-install RET xml-rpc
M-x package-install RET metaweblog
M-x package-install RET org2blog


(setq load-path (cons "~/.emacs.d/org2blog/" load-path))


This code will load the org2blog mode (org-mode, basically, with the comunication feature so that you publish your post)

Then, you also include in the .emacs file the following:

(setq org2blog/wp-blog-alist
'(("wordpress"
:default-title "Hello World"
:default-categories ("org2blog" "emacs")
:tags-as-categories nil)
("my-blog"


You are defining two blogs here. Just change the url, username, etc accordingly. The “wordpress” and “my-blog” are just labels to use in the org2blog mode. When you start a new post, emacs will ask you which blog you want to post.

There are a lot of costumization features that you can use. I particularly don’t use them.

Now, you are ready to go. Below there is a short list with the basic commands that are very useful (some of them essential) to post. The third column includes the alias that I created in the emacs file to make the proccess of blogging even faster.

Table 1: Table with some essential and/or useful commands for org2blog
Command Shortcut Description Alias
M-x org2blog/wp-new-entry   initiate new a post blog-new
M-x org2blog/wp-post-buffer C-c d post buffer as draft blog-postb
M-x org2blog/wp-post-buffer-as-page C-c D post buffer as page draft
C-u M-x org2blog/wp-post-buffer C-c p publish buffer
C-u M-x org2blog/wp-post-buffer-as-page C-c P publish buffer as page
M-x org2blog/wp-delete-entry   when used inside the buffer, it delets the entry in the website
M-x org2blog/wp-delete-page   idem, but delets the page
C-u post-id M-x org2blog/wp-delete-entry   it asks you to provide the postid that you want to delete
M-x org2blog/wp-mode   It is a key-building functionality that will enable C-c d, C-c p and C-c t (complete tag name when inserting it at the top of the page)
org2blog/wp-use-sourcecode-shortcod   turn in the wordpress sourcecode /sourcecode for code blocks
M-x org2blog/wp-logout   log-out blog-out

Note that the complete line command in the .emacs file to definde the alias must be:

(defalias 'alias #'org2blog/wp-login)


Where you substitute “alias” fot your prefered shortcut.

In order to modify the content of a existing post, it is only necessary to publish the buffer again. No additional post will be created, but the existing one will be updated (based on the postid on the head of the file).

So, to finish this post, lets suppose we already did all the steps above. We are ready to post. The steps are:

1. Create a new buffer
2. Initiate org-mode
3. Create a new entry (see table 1 above)
5. Publish it

Lets include a plot, a code and an equation:

To include an equation, just type

$\displaystyle f(x) = \frac{1}{\sqrt{2\pi}\sigma}e^{-(x-\mu)^2/2\sigma}$


And the result will be

$\displaystyle f(x) = \frac{1}{\sqrt{2\pi}\sigma}e^{-(x-\mu)^2/2\sigma}$

The code block is simply enclosed by “”#+Begin_src” and “#+End_src”. For instance, the following code was written between these two marks:

png(file='plots/plotExample.png' )
plot(density(rnorm(1000)))
dev.off()


Finally, we can also include a plot that results from such code. After saving the plot in the specified location, I just include the followin line:

[[./plots/plotExample.png]]


And the result is the the png file will be uploaded, and it will appear in the post:

Finally, We Can Also upload a pdf file using similar code. For instance, here is the above plot in pdf. I just wrote:

[[./plots/plotExample.pdf][pdf]]


The only inconvinient with this approach is that we have to run a code in R, save the plot, and then link it here in the post. Soon, I will updata the information about how to do it inside the post itseld automatically, without the need of opening R and saving the plot separately. The other thing that I will correct soon is the table format for world press, that looks ugly as we see above. Till them, enjoy !