Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Code snippets in a word document

Options
  • 27-07-2017 11:10am
    #1
    Registered Users Posts: 745 ✭✭✭


    I am working on my thesis at present.

    I'd like to include some of my code samples in the document which i am writing using MS word.

    My code is R, apart from using the snipping tool or a straight forward cut and paste, is there any other way of including code in a word document, keeping the format and syntax of the code?

    I have also tried this, http://www.planetb.ca/syntax-highlight-word which is good, but i can't add the results as an object, and therefore cannot reference it as a figure.


Comments

  • Closed Accounts Posts: 2,256 ✭✭✭Molly


    R markdown output as a PDF.


  • Closed Accounts Posts: 22,651 ✭✭✭✭beauf


    I don't have word handy at the moment. I seem to remember using tables in word to this. Two row table, the first row for title and reference, and second for the code. I would screen-grab the code in my IDE and paste in the second row as picture. This preserved formatting ad also was easier to control layout within word. You can use the first row as a heading style so it appears in your navigable document map.

    If I was doing a large document or manual you would run into file size bloat issues. So I used to optimize the screen-grabs to reduce file size before inserting them. There are also means of linking to graphics and even sub documents but I've forgotten how I did this. Printing certain layouts and graphics can be an issue on some printers.

    There are obviously more elegant solutions to this as in Molly's suggestion. Check the approved formats allowed for your thesis, some courses have very specific limitations in what you are allowed to use and submit. Maybe yours just has to be printed in which case you can use whatever works best for you.


  • Registered Users Posts: 3,860 ✭✭✭ozmo


    I found this way to be very useful - much better than tables and text boxes. It isolates the code and the rest of the document very well - keeping the original colouring of the source code.

    https://stackoverflow.com/questions/387453/how-do-you-display-code-snippets-in-ms-word-preserving-format-and-syntax-highlig

    “Roll it back”



  • Closed Accounts Posts: 22,651 ✭✭✭✭beauf


    That's a neat way of doing it.

    I would advise spending some time learning Styles in Word and the word objects if you want to control layout. It's the key to using word for anything other than the basics. Most people don't and find it difficult to control layout.


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    I am working on my thesis at present.

    I'd like to include some of my code samples in the document which i am writing using MS word.

    My code is R, apart from using the snipping tool or a straight forward cut and paste, is there any other way of including code in a word document, keeping the format and syntax of the code?

    I have also tried this, http://www.planetb.ca/syntax-highlight-word which is good, but i can't add the results as an object, and therefore cannot reference it as a figure.

    This is not really answer to your question, but IMHO forget about Word if you want a really professional look. Invest some time in learning LaTeX [1]. You're in the IT, so probably all you need is a few hours to get an idea how it works. An example thesis template [2]

    [1] https://en.wikipedia.org/wiki/LaTeX
    [2] A thesis template (plenty more around as LaTeX is scientific publications standard):
    http://www.latextemplates.com/templates/theses/1/thesis_1.pdf http://www.latextemplates.com/template/masters-doctoral-thesis


  • Advertisement
  • Registered Users Posts: 768 ✭✭✭14ned


    PrzemoF wrote: »
    This is not really answer to your question, but IMHO forget about Word if you want a really professional look. Invest some time in learning LaTeX [1]. You're in the IT, so probably all you need is a few hours to get an idea how it works.

    I couldn't agree more with this. Right now I'm writing a WG21 C++ Standards paper and I had to dust off the old LaTeX skills from uni. LaTeX handles equations with ease, syntax highlights your code snippets, does all the right things with graphs, and is generally the exactly right tool for writing a thesis in the maths or sciences. Almost every paper you'll ever see in Nature or Science is written in LaTeX.

    Furthermore, you can do it all WYSIWYG in an online editor nowadays. I personally use https://www.sharelatex.com, but there are others. No need to install LaTeX, just open a new .tex file in a web browser and get to work.

    Niall


Advertisement