{"id":1293,"date":"2014-08-12T11:04:34","date_gmt":"2014-08-12T10:04:34","guid":{"rendered":"http:\/\/www.blopig.com\/blog\/?p=1293"},"modified":"2014-08-12T11:30:50","modified_gmt":"2014-08-12T10:30:50","slug":"loopy-latex","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2014\/08\/loopy-latex\/","title":{"rendered":"Loopy LaTeX"},"content":{"rendered":"<p>Something that you may or may not know, is that you can write loops in LaTeX. It is, in fact, a Turing-complete language, so you can write if statements too (which is helpful for making multi-line comments), and do all the other things you can do with a programming language.<\/p>\n<p>So, I guess you are thinking, &#8216;eh, that&#8217;s cool, but why would I do it?&#8217; Indeed, I have known about this for ages, but never found any need for it, until recently. My problem was that I had generated 80 small images, that I wanted to display on a number of pages. I could have played with print settings, and made multiple pages per sheet, but since I wanted two columns, and to fit 16 to a page (the 80 images were in 5 sets of 16, each with two subsets), that was going to be a pain. I also wanted to add some labels to each set, but not have said label on every image. However, I thought that LaTeX could solve my problem.<\/p>\n<p>As ever, there are a number of different latex packages that you can use, but I used the pgffor package. In the example below, my pictures were named [A-E]_[ab][1-8]_picture, e.g. A_b2_picture.png, or D_a3_picture.png. The code produces pages of 16 pictures, with the &#8216;a&#8217; pictures on the left, and the &#8216;b&#8217; pictures on the right.<br \/>\nThere is a more simple example at the bottom.<\/p>\n<pre class=\"lang:tex decode:true\" title=\"Loop code\">\\documentclass[a4paper,10pt]{article}\r\n\\usepackage[utf8]{inputenc}\r\n\\usepackage{pgffor}\r\n\\usepackage{subfigure}\r\n\\usepackage{graphicx}\r\n\\usepackage{caption}\r\n\\usepackage{subcaption}\r\n\\usepackage{fullpage}\r\n\r\n\\begin{document}\r\n\\section{}\r\n\r\n\\foreach \\method in {A, B, C, D, E}{ %looping over each set of 16 \r\n  \\begin{figure}\r\n  \\foreach \\i in {1,...,8}{ %looping over each subset, the a set first, then the b set\r\n    \\centering     \r\n    \\subfigure[]{\\label{fig:\\method \\i a}\\includegraphics[width=0.45\\textwidth]{\\method _a\\i _picture}} \r\n    \\subfigure[]{\\label{fig:\\method \\i b}\\includegraphics[width=0.45\\textwidth]{\\method _b\\i _picture}}\r\n  }\r\n  \\caption{\\method}\r\n  \\end{figure}\r\n}\r\n\r\n%a more simple example\r\n\\foreach \\number in {1,...,10}{\r\n\\number \\ elephant\r\n}  \r\n\r\n\\end{document}<\/pre>\n<p>Happy LaTeXing..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Something that you may or may not know, is that you can write loops in LaTeX. It is, in fact, a Turing-complete language, so you can write if statements too (which is helpful for making multi-line comments), and do all the other things you can do with a programming language. So, I guess you are [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"ppma_author":[491],"class_list":["post-1293","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":491,"user_id":12,"is_guest":0,"slug":"henry","display_name":"Henry Wilman","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/f5e15e4499d0dd3506b286217dfeb0264616f421e854f8fad9813fb13678b41a?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/1293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=1293"}],"version-history":[{"count":11,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/1293\/revisions"}],"predecessor-version":[{"id":2066,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/1293\/revisions\/2066"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=1293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=1293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=1293"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=1293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}