Marking up code

You can mark up code by enclosing it in appropriate shortcodes. I have installed the syntax highlighter plugin so that keywords should be highlighted appropriately.

  • The C Language

    	 	 
    [c]	 	 
    #include <stdio.h>	 	 
    main()	 	 
    {	 	 
    	printf("Hello World");	 	 
    }	 	 
    [/c]	 	 
    

    becomes

    	 	 
    #include <stdio.h>	 	 
    main()	 	 
    {	 	 
    	printf("Hello World");	 	 
    }	 	 
    
  • Java

    	 	 
    [java]	 	 
    class hello	 	 
    {	 	 
    	public static void main(String args[])	 	 
    	{	 	 
    		System.out.println("Hello World!");	 	 
    	}	 	 
    }	 	 
    [/java]	 	 
    

    becomes

    	 	 
    class hello	 	 
    {	 	 
    	public static void main(String args[])	 	 
    	{	 	 
    		System.out.println("Hello World!");	 	 
    	}	 	 
    }	 	 
    
  • C++

    	 	 
    [cpp]	 	 
    #include	 	 
    int main()	 	 
    {	 	 
    	std::cout << "Hello World!" << std::endl;	 	 
    	return 0;	 	 
    }	 	 
    [/cpp]	 	 
    

    becomes

    	 	 
    #include	 	 
    int main()	 	 
    {	 	 
    	std::cout << "Hello World!" << std::endl;	 	 
    	return 0;	 	 
    }	 	 
    
  • Shortcodes for use with many other languages are listed here.

    Marking up mathematics

    I have enabled the Mathjax plugin in WordPress so that you can add mathematical notation to your posts using Latex markup.

    You must wrap the latex markup appropriately to inform WordPress to process it using the plugin.

    For in-line maths use escaped round brackets (i.e., precede the bracket with a backslash):

     \(A = \pi r^2\) 

    → \(A = \pi r^2\)

    An alternative is to use shortcodes

     [latex] E=mc^2 [/latex] 

    →\(E=mc^2\)

    For display maths use escaped square brackets:

     \[ C=2\times\pi\times r \] 

    → \[ C=2\times\pi\times r \]

    Note: The visual editor can corrupt the text used to enter markup so check the raw text if you have a WYGINWYW moment (What You Get Is Not What You Wanted).

    How do you come up with the Latex code?

    Consider this formula:

     \[ G(f)=\int_{-\infty }^{\infty}g(t)e^{-j2\pi ft}dt \] 

    →\[ G(f)=\int_{-\infty }^{\infty}g(t)e^{-j2\pi ft}dt \]

    I showed the markup explicitly above by including it in a text block before the equation:

    \[ [\mbox{text}]\ldots [/\mbox{text}] \]

    but if you right click the displayed formula, you can view the actual Latex markup and copy it to the clipboard. Suppose you wanted to include this formula in a post, but using \( j \omega \) as the frequency variable. Paste it into this online equation editor and edit it appropriately. Once the equation looks right, copy the revised latex code into the WordPress post editor (between escaped brackets) and preview it to see if all is well.

    Supported Blogs

    This blog is used to support teaching in the School of Electronic Engineering. At the moment, two modules are supported:

    There are also archives of modules not being delivered in the current academic year:

    and the following modules, although being delivered this year, no longer use a WordPress blog (but you can see the archives)

    Note that an implementation bug in WordPress means that the page header and CSS files do not update correctly when you click the above links – refresh the page (by, e.g., hitting F5) to fix this.