]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Only output a list of parameters if there are any. Otherwise we
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 27 Sep 2012 16:58:13 +0000 (16:58 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 27 Sep 2012 16:58:13 +0000 (16:58 +0000)
end up with an empty {itemize} list which latex does not like.

git-svn-id: https://svn.dealii.org/trunk@26795 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/source/base/parameter_handler.cc
tests/bits/parameter_handler_4b.cc [new file with mode: 0644]
tests/bits/parameter_handler_4b/cmp/generic [new file with mode: 0644]

index 28ebe63f839f67438a5b979264ec7c18d8cec9dd..318bd56f1c209466d3bd6d0497b45141c8c311e6 100644 (file)
@@ -87,6 +87,14 @@ DoFHandler, in particular removal of specializations.
 <h3>Specific improvements</h3>
 
 <ol>
+<li> Fixed: ParameterHandler::print_parameters, when using
+ParameterHandler::OutputStyle::LaTeX would always print a list
+of parameters in each section as a latex itemized environment.
+However, if there are none, we end up with an empty list which
+latex does not like. This is now fixed.
+<br>
+(Wolfgang Bangerth, 2012/09/27)
+
 <li> New: Added BlockCompressedSimpleSparsityPattern::column_number().
 <br>
 (Timo Heister, 2012/09/25)
index 1b409879485e8580df9ea6139eb894c234c037fb..a166766a8cc55358ad82fa3b58b13f2dec474039 100644 (file)
@@ -1884,54 +1884,70 @@ ParameterHandler::print_parameters_section (std::ostream      &out,
 
       case LaTeX:
       {
-        out << "\\begin{itemize}"
-            << std::endl;
-
-                                         // print entries one by
-                                         // one. make sure they are
-                                         // sorted by using the
-                                         // appropriate iterators
-        for (boost::property_tree::ptree::const_assoc_iterator
-               p = current_section.ordered_begin();
-             p != current_section.not_found(); ++p)
-          if (is_parameter_node (p->second) == true)
-            {
-              const std::string value = p->second.get<std::string>("value");
-
-                                               // print name
-              out << "\\item {\\it Parameter name:} {\\tt " << demangle(p->first) << "}\n\n"
-                  << std::endl;
-
-              out << "\\index[prmindex]{"
-                  << demangle(p->first)
-                  << "}\n";
-              out << "\\index[prmindexfull]{";
-              for (unsigned int i=0; i<subsection_path.size(); ++i)
-                out << subsection_path[i] << "!";
-              out << demangle(p->first)
-                  << "}\n";
-
-                                               // finally print value and default
-              out << "{\\it Value:} " << value << "\n\n"
-                  << std::endl
-                  << "{\\it Default:} "
-                  << p->second.get<std::string>("default_value") << "\n\n"
-                  << std::endl;
-
-                                               // if there is a
-                                               // documenting string,
-                                               // print it as well
-              if (!p->second.get<std::string>("documentation").empty())
-                out << "{\\it Description:} "
-                    << p->second.get<std::string>("documentation") << "\n\n"
-                    << std::endl;
-
-                                               // also output possible values
-              out << "{\\it Possible values:} "
-                  << p->second.get<std::string> ("pattern_description")
-                  << std::endl;
-            }
-        out << "\\end{itemize}" << std::endl;
+                                        // if there are any parameters in
+                                        // this section then print them as an
+                                        // itemized list
+       bool parameters_exist_here = false;
+       for (boost::property_tree::ptree::const_assoc_iterator
+              p = current_section.ordered_begin();
+            p != current_section.not_found(); ++p)
+         if (is_parameter_node (p->second) == true)
+           {
+             parameters_exist_here = true;
+             break;
+           }
+
+       if (parameters_exist_here)
+         {
+           out << "\\begin{itemize}"
+               << std::endl;
+
+                                            // print entries one by
+                                            // one. make sure they are
+                                            // sorted by using the
+                                            // appropriate iterators
+           for (boost::property_tree::ptree::const_assoc_iterator
+                  p = current_section.ordered_begin();
+                p != current_section.not_found(); ++p)
+             if (is_parameter_node (p->second) == true)
+               {
+                 const std::string value = p->second.get<std::string>("value");
+
+                                                  // print name
+                 out << "\\item {\\it Parameter name:} {\\tt " << demangle(p->first) << "}\n\n"
+                     << std::endl;
+
+                 out << "\\index[prmindex]{"
+                     << demangle(p->first)
+                     << "}\n";
+                 out << "\\index[prmindexfull]{";
+                 for (unsigned int i=0; i<subsection_path.size(); ++i)
+                   out << subsection_path[i] << "!";
+                 out << demangle(p->first)
+                     << "}\n";
+
+                                                  // finally print value and default
+                 out << "{\\it Value:} " << value << "\n\n"
+                     << std::endl
+                     << "{\\it Default:} "
+                     << p->second.get<std::string>("default_value") << "\n\n"
+                     << std::endl;
+
+                                                  // if there is a
+                                                  // documenting string,
+                                                  // print it as well
+                 if (!p->second.get<std::string>("documentation").empty())
+                   out << "{\\it Description:} "
+                       << p->second.get<std::string>("documentation") << "\n\n"
+                       << std::endl;
+
+                                                  // also output possible values
+                 out << "{\\it Possible values:} "
+                     << p->second.get<std::string> ("pattern_description")
+                     << std::endl;
+               }
+           out << "\\end{itemize}" << std::endl;
+         }
 
         break;
       }
diff --git a/tests/bits/parameter_handler_4b.cc b/tests/bits/parameter_handler_4b.cc
new file mode 100644 (file)
index 0000000..917a7a2
--- /dev/null
@@ -0,0 +1,67 @@
+//----------------------------  parameter_handler_4b.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2003, 2004, 2005, 2012 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  parameter_handler_4b.cc  ---------------------------
+
+
+// test the output generated by
+// ParameterHandler::print_parameters(LaTeX). make sure that empty sections do
+// not lead to empty itemized environments in the latex output, which are not
+// valid
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+#include <iomanip>
+
+
+int main ()
+{
+  try
+    {
+      std::ofstream logfile("parameter_handler_4b/output");
+      deallog.attach(logfile);
+      deallog.depth_console(0);
+      deallog.threshold_double(1.e-10);
+
+      ParameterHandler prm;
+      prm.enter_subsection ("Testing");
+      prm.leave_subsection ();
+      prm.print_parameters (logfile, ParameterHandler::LaTeX);
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      deallog << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      deallog << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+
+  return 0;
+}
diff --git a/tests/bits/parameter_handler_4b/cmp/generic b/tests/bits/parameter_handler_4b/cmp/generic
new file mode 100644 (file)
index 0000000..c6af8c1
--- /dev/null
@@ -0,0 +1,9 @@
+
+\subsection{Global parameters}
+\label{parameters:global}
+
+
+
+\subsection{Parameters in section \tt Testing}
+\label{parameters:Testing}
+

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.