diff --git a/README.md b/README.md index e018f54..34090ff 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ DocPu, Document publishing plugin This plugin enables PDF export and generation for Redmine wiki pages using the LaTeX typesetting system. But it is even more than an simple PDF exporter since it uses the LaTeX text and figure layout engine. Originally this redmine plugin was created by Christian Raschko (sponsored by [ATV-Elektronik](http://atv-elektronik.co.at/)). It was intended to be used for 1.1.x verisions of redmine and below. -Since this plugin creates eye catching documents and of cause can be extended a little more I decided to adopt the code and make it valid for use in __redmine 2.6.x__ versions. +Since this plugin creates eye catching documents and of cause can be extended a little more I decided to adopt the code and make it valid for use in __redmine 3.2.x__ versions. Mainly all features as described below should work. You may find formatting in Redmine's wiki-syntax which isn't covered yet. If so-feel free to contact me. @@ -28,14 +28,19 @@ Features Dependencies ============ -DocPu uses and extends the [RedCloth4](http://redcloth.org/) LaTeX export module, which is a converter for the Textile markup language. The system which hosts redmine should also have an working installation of LaTeX. Since the code highlighting is done by pygments, this python package should be installed too. This version of the plugin is made to work with __redmine 2.6.x__. This indicate a dependency to [rails 3.2](http://guides.rubyonrails.org/v3.2.21/3_2_release_notes.html) as you can see [here](http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Ruby-interpreter). For older redmines you can refer to this [version](http://www.redmine.org/plugins/redmine_doc_pu) of the plugin. +DocPu uses and extends the [RedCloth4](http://redcloth.org/) LaTeX export module, which is a converter for the Textile markup language. The system which hosts redmine should also have an working installation of LaTeX. Since the code highlighting is done by pygments, this python package should be installed too. This version of the plugin is made to work with __redmine 3.2.x__. This indicate a dependency to [rails 4.2.5](http://guides.rubyonrails.org/4_2_release_notes.html) as you can see [here](http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Ruby-interpreter). For older redmines you can refer to this [version](http://www.redmine.org/plugins/redmine_doc_pu) of the plugin. + +List of Dependencies in a quick view: +* redmine 3.2.0 (tested with ruby 2.0, rails 4.2.5, RedCloth 4.2.9) +* Tex (tested with pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014)) + * Packeges which are important due to creation process of the PDF inside the plugin (newfloat, minted, caption, ulem, graphicx, float, multirow, makeidx, hyperref, tabularx, footnote, scrhack) Installing RedCloth4 -------------------- Currently Redmine uses RedCloth3, so you have to additionally install RedCloth4. The simplest solution is by typing gem install RedCloth, but this only works if you have a compiler set-up, since some parts are written in C code. -For windows users a pre compiled gem package can be downloaded from the repository. Download it first and install it via eg. gem install RedCloth-4.2.2-x86-mswin32-60.gem +For windows users a pre compiled gem package can be downloaded from the repository. LaTeX ----- @@ -47,6 +52,7 @@ On Windows machines you can download and install the [MikTex](http://miktex.org/ DocPu Requires the following LaTeX packages, be sure you have them installed as well: +* newfloat * tabularx * listings * ulem @@ -57,6 +63,8 @@ DocPu Requires the following LaTeX packages, be sure you have them installed as * hyperref * minted * caption +* footnote +* scrhack ### Testing LaTeX @@ -154,6 +162,8 @@ The image position can be fixed or floated. Fixed images occur at the text posit Normally you have the standard LaTeX [image types](https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics#Supported_image_formats) available for use. +Note that all images are scaled to fit in the text width space with keeping the spect ratio if they are to large for the page. + ## Tables DocPu supports the Redmine/Textile table syntax with table span and heading. @@ -162,3 +172,11 @@ DocPu supports the Redmine/Textile table syntax with table span and heading. # Template handling The templates in the plugins template directory are simply LeTeX-Templates. Please refer to [this](https://en.wikibooks.org/wiki/LaTeX) guide to learn more about LaTeX and how to use it. + +It is really important, that you have a look at the templates which are included in this plugin. There you can have a look how a template must be written to match the criteria set by this plugin. We designed around this pattern several special looking templates, which are working well. You should be able to do so as well. But keep in mind to NOT DELETE/EDIT ANY CONTENT/PACKAGES which is given in this templates. You can copy one of them (keeping all stuff which is in it) and use the copy to add your own styling. Again: If you delete/edit any thing of the given parameters it will probably not work. But you have enough options to build a nice looking template on top of the existing pattern. + +# Known Problems + +* Footnotes in tables are placed directly under the table and not to the end of the page (this is due to LaTeX-dependet problems => you may google for it). +* Sometimes the index will not be created well (it helps to build the document 2-3 times again => the number of warnings should decrease) +* to get rid of the warnings and sometimes the errors it can be helpful to rebuild the document 2-3 times before having a look on the templates (also use the clean function in the build view to delete all generated files if you are facing any problems) diff --git a/app/controllers/doc_pu_controller.rb b/app/controllers/doc_pu_controller.rb index 09920dc..b6fefaa 100644 --- a/app/controllers/doc_pu_controller.rb +++ b/app/controllers/doc_pu_controller.rb @@ -10,19 +10,20 @@ class DocPuController < ApplicationController # Show all documents def index - @documents = DocPuDocument.find_all_by_project_id(@project) + @documents = DocPuDocument.where(project_id: @project) end # Create new document def new + @templates_list = DocPuTemplates.new(Rails.root.join(Setting.plugin_redmine_doc_pu['template_dir'])).list @doc = DocPuDocument.new @doc.project = @project @doc.user = User.current if request.post? # Save object - @doc.attributes = checkbox_to_boolean(params[:doc]) + @doc.attributes = checkbox_to_boolean(params.require(:doc).permit!) if @doc.save flash[:notice] = t(:flash_document_saved) redirect_to :action => :edit, :project_id => @project, :id => @doc @@ -34,10 +35,10 @@ def new # Edit document def edit - @doc = DocPuDocument.find(params[:id]) - if request.put? + @doc = DocPuDocument.find(params[:id]) + if request.patch? # Update document - @doc.attributes = checkbox_to_boolean(params[:doc]) + @doc.attributes = checkbox_to_boolean(params.require(:doc).permit!) flash[:notice] = t(:flash_document_updated) if @doc.save end diff --git a/app/controllers/doc_pu_wiki_controller.rb b/app/controllers/doc_pu_wiki_controller.rb index 2d92d4b..451784a 100644 --- a/app/controllers/doc_pu_wiki_controller.rb +++ b/app/controllers/doc_pu_wiki_controller.rb @@ -17,7 +17,7 @@ def new if request.post? # Save object reorder_pages(@doc_pu.doc_pu_wiki_pages.all) - @doc_pu_wiki = @doc_pu.doc_pu_wiki_pages.create(checkbox_to_boolean params[:doc_pu_wiki]) + @doc_pu_wiki = @doc_pu.doc_pu_wiki_pages.create(checkbox_to_boolean params.require(:doc_pu_wiki).permit!) @doc_pu_wiki.wiki_page_order = get_new_page_order() @doc_pu_wiki.wiki_page_version = 0 if @doc_pu_wiki.save @@ -34,7 +34,7 @@ def edit @doc_pu_wiki = DocPuWikiPage.find(params[:id]) if request.put? # Update object - @doc_pu_wiki.attributes = checkbox_to_boolean(params[:doc_pu_wiki]) + @doc_pu_wiki.attributes = checkbox_to_boolean(params.require(:doc_pu_wiki).permit!) if @doc_pu_wiki.save flash[:notice] = t(:flash_page_updated) redirect_to :controller => :doc_pu, :action => :edit, :project_id => @project, :id => @doc_pu diff --git a/app/models/doc_pu_document.rb b/app/models/doc_pu_document.rb index 0356a74..d36825b 100644 --- a/app/models/doc_pu_document.rb +++ b/app/models/doc_pu_document.rb @@ -10,7 +10,7 @@ class DocPuDocument < ActiveRecord::Base belongs_to :user belongs_to :project - has_many :doc_pu_wiki_pages, :dependent => :destroy, :order => 'wiki_page_order' + has_many :doc_pu_wiki_pages, :dependent => :destroy validates_presence_of :name, :template, :user_id, :project_id validates_uniqueness_of :name diff --git a/app/views/doc_pu/_form.html.erb b/app/views/doc_pu/_form.html.erb index 291ae14..2b7c7f3 100644 --- a/app/views/doc_pu/_form.html.erb +++ b/app/views/doc_pu/_form.html.erb @@ -21,6 +21,13 @@

<%= f.check_box :latex_table_border %> <%= acronym_info_tag t(:info_latex_table_border) %>

<%= f.check_box :latex_image_ref %> <%= acronym_info_tag t(:info_latex_image_ref) %>

+ +

<%= f.check_box :latex_table_of_contents %> <%= acronym_info_tag t(:info_latex_table_of_contents) %>

+

<%= f.check_box :latex_list_of_figures %> <%= acronym_info_tag t(:info_latex_list_of_figures) %>

+

<%= f.check_box :latex_list_of_tables %> <%= acronym_info_tag t(:info_latex_list_of_tables) %>

+

<%= f.check_box :latex_list_of_listings %> <%= acronym_info_tag t(:info_latex_list_of_listings) %>

+

<%= f.check_box :latex_generate_index %> <%= acronym_info_tag t(:info_latex_generate_index) %>

+
<%= submit_tag l(:button_save) %>
diff --git a/config/locales/de.yml b/config/locales/de.yml index 2e767be..cc5872a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -18,6 +18,11 @@ de: field_latex_index_importance: "Wichtige Wörter indizieren" field_latex_table_border: "Rahmen für Tabellen" field_latex_image_ref: "Bilder refernzieren" + field_latex_list_of_listings: "Codeverzeichnis" + field_latex_table_of_contents: "Inhaltsverzeichnis" + field_latex_list_of_figures: "Abbildungsverzeichnis" + field_latex_list_of_tables: "Tabellenverzeichnis" + field_latex_generate_index: "Index" field_wiki_page: "Wiki Seite" field_chapter_name: "Kapitel Name" field_use_doc_flags: "Dokument Flags verwenden" @@ -74,6 +79,11 @@ de: info_latex_index_importance: "" info_latex_table_border: "Stellt Tabellenlinien dar." info_latex_image_ref: "Erzeuge Bildverzeichnis" + info_latex_list_of_listings: "Erzeugt ein Verzeichnis aller Code-Beispiele. Dieses wird am Anfang des Dokumentes eingefügt." + info_latex_list_of_figures: "Erzeugt eine Verzeichnis aller Abbildungen. Dieses wird am Anfang des Dokumentes eingefügt." + info_latex_list_of_tables: "Erzeugt eine Verzeichnis aller Tabellen. Dieses wird am Anfang des Dokumentes eingefügt." + info_latex_table_of_contents: "Erzeugt ein Inhaltsverzeichnis für das gesamte Dokument. Dieses wird am Anfang des Dokumentes eingefügt." + info_latex_generate_index: "Erzeugt einen Index von hervorgehobenen Wörtern (dies sind alle Wörter die mit \\*WORT\\* fett gedruckt werden). Es wird am Ende des Dokumentes eingefügt." button_test: "Test" field_latex_bin: "LaTeX Binärdatei (pdflatex)" field_makindex_bin: "makeindex Binärdatei" diff --git a/config/routes.rb b/config/routes.rb index 0483a3f..3d837f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ match 'doc_pu', :controller => 'doc_pu', :action => 'index', :via => :get match 'doc_pu/new', :controller => 'doc_pu', :action => 'new', :via => [:get, :post] -match 'doc_pu/edit', :controller => 'doc_pu', :action => 'edit', :via => [:get, :post, :put] +match 'doc_pu/edit', :controller => 'doc_pu', :action => 'edit', :via => [:get, :post, :patch] match 'doc_pu/open', :controller => 'doc_pu', :action => 'open', :via => [:get, :post] match 'doc_pu/build', :controller => 'doc_pu', :action => 'build', :via => [:get, :post] match 'doc_pu/build_remote', :controller => 'doc_pu', :action => 'build_remote', :via => [:get, :post] @@ -12,7 +12,7 @@ match 'doc_pu_wiki', :controller => 'doc_pu_wiki', :action => 'index', :via => [:get] match 'doc_pu_wiki/new', :controller => 'doc_pu_wiki', :action => 'new', :via => [:get, :post] -match 'doc_pu_wiki/edit', :controller => 'doc_pu_wiki', :action => 'edit', :via => [:get, :post, :put] +match 'doc_pu_wiki/edit', :controller => 'doc_pu_wiki', :action => 'edit', :via => [:get, :post, :patch] match 'doc_pu_wiki/delete', :controller => 'doc_pu_wiki', :action => 'delete', :via => [:get, :post] match 'doc_pu_wiki/edit_order', :controller => 'doc_pu_wiki', :action => 'edit_order', :via => [:get, :post] diff --git a/init.rb b/init.rb index 7574b64..dcd1085 100644 --- a/init.rb +++ b/init.rb @@ -10,7 +10,7 @@ name 'Redmine DocPu plugin' author 'Christian Raschko' description 'A wiki export and document publishing tool, sponsored by: ATV-Elektronik and modified for further use by: GIS-Fachstelle BL' - version '0.0.4' + version '2.0.0' url 'https://github.com/vvmruder/redmine_doc_pu' # Settings @@ -22,7 +22,7 @@ :partial => 'settings/doc_pu_settings' # Redmine version - requires_redmine :version_or_higher => '2.6.0' + requires_redmine :version_or_higher => '3.2.0' # Create project module project_module :doc_pu do diff --git a/lib/latex_doc.rb b/lib/latex_doc.rb index e1e7fd9..ffa07ac 100644 --- a/lib/latex_doc.rb +++ b/lib/latex_doc.rb @@ -64,6 +64,49 @@ def to_latex self.wiki_pages.each do |page| doc_txt += page.to_latex end + intro_content = false + pre_text = "" + + if self.latex_table_of_contents + # Add table of contents to the begin of the document + with_table_of_content = "\\tableofcontents\n\n" + pre_text << with_table_of_content + intro_content = true + end + + if self.latex_list_of_figures + # Add list of figures to the begin of the document + with_list_of_figures = "\\listoffigures\n\n" + pre_text << with_list_of_figures + intro_content = true + end + + if self.latex_list_of_tables + # Add list of tables to the begin of the document + with_list_of_tables = "\\listoftables\n\n" + pre_text << with_list_of_tables + intro_content = true + end + + if self.latex_list_of_listings + # Add list of code listings to the begin of the document + with_list_of_listings = "\\listoflistings\n\n" + pre_text << with_list_of_listings + intro_content = true + end + + if intro_content + with_roman_numbers = "\n\n\\pagenumbering{roman}\n\n\\setcounter{page}{1}\n\n" + pre_text = with_roman_numbers << pre_text + pre_text << "\n\n\\cleardoublepage\\pagenumbering{arabic}\n\n\\setcounter{page}{1}\n\n" + doc_txt = pre_text << doc_txt + end + + if self.latex_generate_index + # Add list of code listings to the begin of the document + with_index = "\n\n\\printindex" + doc_txt << with_index + end doc_txt end diff --git a/lib/latex_flags.rb b/lib/latex_flags.rb index 11961ad..9a649f3 100644 --- a/lib/latex_flags.rb +++ b/lib/latex_flags.rb @@ -10,7 +10,12 @@ module ModuleLatexFlags :latex_index_emphasis => true, :latex_index_importance => true, :latex_table_border => true, - :latex_image_ref => false + :latex_image_ref => false, + :latex_list_of_listings => false, + :latex_list_of_figures => false, + :latex_list_of_tables => false, + :latex_table_of_contents => false, + :latex_generate_index => false } diff --git a/lib/latex_wiki_page.rb b/lib/latex_wiki_page.rb index 17d3b71..513dfd5 100644 --- a/lib/latex_wiki_page.rb +++ b/lib/latex_wiki_page.rb @@ -27,12 +27,12 @@ def to_latex() page_txt.gsub!(fn, dsk_fn) end - # Check wiki referenzes for redirects + # Check wiki references for redirects page_txt.gsub!(/(\s|^)\[\[(.*?)(\|(.*?)|)\]\]/i) do |_| ref = $2 label = $4 ref = Wiki.titleize(ref) - redir = WikiRedirect.all(:conditions => ['title = ?', ref])[0] + redir = WikiRedirect.where(title: ref) ref = redir.redirects_to unless redir.nil? " [[#{ref}|#{label}]]" end @@ -46,12 +46,11 @@ def to_latex() rules.push(:latex_index_emphasis) if self.latex_index_emphasis rules.push(:latex_index_importance) if self.latex_index_importance rules.push(:latex_remove_macro) if self.latex_remove_macro - # Convert page to latex r = TextileDocLatex.new(page_txt) r.draw_table_border_latex = self.latex_table_border page_txt = r.to_latex(*rules) - + if self.latex_add_chapter # Add chapter tag page_txt = "\n\\chapter{#{self.chapter_name}} \\label{page:#{self.wiki_page.title}}\n" + page_txt @@ -60,7 +59,7 @@ def to_latex() page_txt.sub!(/\\section\{(.+)\}/i) do |_| "\\section{#{$1}}\\label{page:#{self.wiki_page.title.gsub(' ', '_')}}" end - end + end page_txt end diff --git a/lib/textile_doc_latex.rb b/lib/textile_doc_latex.rb index 8b06260..63e23f3 100644 --- a/lib/textile_doc_latex.rb +++ b/lib/textile_doc_latex.rb @@ -2,7 +2,6 @@ module RedCloth::Formatters::LATEX_EX include RedCloth::Formatters::LATEX - def td(opts) if opts[:text] if opts[:text].include? "\n" @@ -30,10 +29,12 @@ def td(opts) end def table_close(opts) - output = "\\begin{table}[H]\n" + output = "\\begin{savenotes}\n" + output << "\\begin{table}[H]\n" output << " \\centering\n" cols = 'X' * @table[0].size if not draw_table_border_latex cols = '|' + 'X|' * @table[0].size if draw_table_border_latex + output << "\\begin{minipage}{\\linewidth}\n" output << " \\begin{tabularx}{\\textwidth}{#{cols}}\n" output << " \\hline \n" if draw_table_border_latex @table.each do |row| @@ -42,7 +43,9 @@ def table_close(opts) end output << " \\end{tabularx}\n" output << " \\caption{}\n" + output << " \\end{minipage}\n" output << "\\end{table}\n" + output << "\\end{savenotes}\n" output end @@ -55,7 +58,7 @@ def image(opts) # Build latex code [ "\\begin{figure}[#{(opts[:align].nil? ? 'H' : 'htb')}]", " \\centering", - " \\includegraphics[#{styling}]{#{opts[:src]}}", + " \\lwincludegraphics[#{styling}]{#{opts[:src]}}", (" \\caption{#{escape opts[:title]}}" if opts[:title]), (" \\label{#{opts[:alt]}}" if opts[:alt]), "\\end{figure}", @@ -75,9 +78,10 @@ def latex_code(text) code = $2 lang = "{#{$1}}" end - minted_settings = %W(mathescape linenos numbersep=5pt frame=lines framesep=2mm tabsize=4 fontsize=\\footnotesize) + minted_settings = %W(mathescape linenos numbersep=5pt frame=lines framesep=2mm tabsize=4 fontsize=\\footnotesize breaklines) .join(",") - latex_code_text = "\\begin{listing}[H]\n\\begin{minted}[#{minted_settings}]#{lang}#{code}\n\\end{minted}\n\\caption{}\n\\end{listing}\n" + puts minted_settings + latex_code_text = "\\begin{code}\\begin{minted}[#{minted_settings}]#{lang}#{code}\n\\end{minted}\n\\caption{}\n\\end{code}\n\n" latex_code_text end end @@ -126,11 +130,11 @@ def latex_index_importance(text) end end - def latex_remove_macro(text) - text.gsub!(/(\s|^)\{\{(.*?)\}\}/i) do |_| + def latex_remove_macro(text) + text.gsub!(/(\s|^)\{\{(.*?)\}\}/i) do |_| '' - end - end + end + end end # Include rules diff --git a/templates/scrartcl_de_tcfi.tex b/templates/scrartcl_de_tcfi.tex index 4432174..611f082 100644 --- a/templates/scrartcl_de_tcfi.tex +++ b/templates/scrartcl_de_tcfi.tex @@ -15,8 +15,8 @@ \usepackage[utf8]{inputenc} % textile required packages -\usepackage{minted} -\usepackage{tabularx} +\usepackage{newfloat} +\usepackage[newfloat=true]{minted} \usepackage{caption} \usepackage[normalem]{ulem} \usepackage{graphicx} @@ -24,6 +24,23 @@ \usepackage{multirow} \usepackage{makeidx} \usepackage{hyperref} +\usepackage{tabularx} +\usepackage{footnote} +\usepackage{scrhack} +\makesavenoteenv{tabularx} + +\SetupFloatingEnvironment{listing}{name=Code-Beispiel} +\SetupFloatingEnvironment{listing}{listname=Code-Verzeichnis} + +\newenvironment{code}{\captionsetup{type=listing,belowskip=12pt,aboveskip=4pt}}{} + +\newcommand{\lwincludegraphics}[2][]{% + \sbox{0}{\includegraphics[#1]{#2}}% + \ifdim\wd0>\linewidth + \resizebox{\linewidth}{!}{\box0 }% + \else + \leavevmode\box0 + \fi} \hypersetup{ colorlinks=true, % false: boxed links; true: colored links @@ -48,22 +65,7 @@ % title on the first page \maketitle - % table of contents - \tableofcontents - - % list of figures - \listoffigures - - % list of tables - \listoftables - - % list of listings - \listoflistings - % input \input{document.tex} - - % print index - \printindex \end{document} diff --git a/templates/scrreprt_de_tcfi.tex b/templates/scrreprt_de_tcfi.tex index 3ee6764..dd8cdb8 100644 --- a/templates/scrreprt_de_tcfi.tex +++ b/templates/scrreprt_de_tcfi.tex @@ -15,8 +15,8 @@ \usepackage[utf8]{inputenc} % textile required packages -\usepackage{minted} -\usepackage{tabularx} +\usepackage{newfloat} +\usepackage[newfloat=true]{minted} \usepackage{caption} \usepackage[normalem]{ulem} \usepackage{graphicx} @@ -24,6 +24,23 @@ \usepackage{multirow} \usepackage{makeidx} \usepackage{hyperref} +\usepackage{tabularx} +\usepackage{footnote} +\usepackage{scrhack} +\makesavenoteenv{tabularx} + +\SetupFloatingEnvironment{listing}{name=Code-Beispiel} +\SetupFloatingEnvironment{listing}{listname=Code-Verzeichnis} + +\newenvironment{code}{\captionsetup{type=listing,belowskip=12pt,aboveskip=4pt}}{} + +\newcommand{\lwincludegraphics}[2][]{% + \sbox{0}{\includegraphics[#1]{#2}}% + \ifdim\wd0>\linewidth + \resizebox{\linewidth}{!}{\box0 }% + \else + \leavevmode\box0 + \fi} \hypersetup{ colorlinks=true, % false: boxed links; true: colored links @@ -48,22 +65,7 @@ % title on the first page \maketitle - % table of contents - \tableofcontents - - % list of figures - \listoffigures - - % list of tables - \listoftables - - % list of listings - \listoflistings - % input \input{document.tex} - - % print index - \printindex \end{document}