protected MathFormatter() { _inlineSize = 10; _displayedSize = 10; _inlineZoom = 2; _displayedZoom = 3; _namingPrefix = "math"; _namingMethod = MathNamingMethod.Sequential; _sizesLaTeX = new string[] { "\\tiny", "\\small", "\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge" }; }
/// <overloads> /// Initializes a new instance of the <see cref="ConceptualMathConfiguration"/> class. /// </overloads> /// <summary> /// Initializes a new instance of the <see cref="ConceptualMathConfiguration"/> class /// to the default values. /// </summary> public ConceptualMathConfiguration() { _inlineSize = 10; _displayedSize = 10; _inlineZoom = 2; _displayedZoom = 3; _inputPath = @".\maths\"; _baseOutput = @".\Output"; _outputPath = "maths"; _namingPrefix = "math"; _namingMethod = MathNamingMethod.Sequential; _numEnabled = true; _numByPage = false; _numFormatIncludesPage = true; _numFormat = "({0}.{1})"; }
/// <summary> /// Initializes a new instance of the <see cref="ReferenceMathConfiguration"/> class /// with parameters copied from the specified instance of the /// <see cref="ReferenceMathConfiguration"/> class, a copy constructor. /// </summary> /// <param name="source"> /// An instance of the <see cref="ReferenceMathConfiguration"/> class from which the /// initialization parameters or values will be copied. /// </param> /// <exception cref="ArgumentNullException"> /// If the parameter <paramref name="source"/> is <see langword="null"/>. /// </exception> public ReferenceMathConfiguration(ReferenceMathConfiguration source) : base(source) { _inlineSize = source._inlineSize; _displayedSize = source._displayedSize; _inlineZoom = source._inlineZoom; _displayedZoom = source._displayedZoom; _inputPath = source._inputPath; _baseOutput = source._baseOutput; _outputPath = source._outputPath; _namingPrefix = source._namingPrefix; _namingMethod = source._namingMethod; _numEnabled = source._numEnabled; _numByPage = source._numByPage; _numFormat = source._numFormat; _numFormatIncludesPage = source._numFormatIncludesPage; }
protected MathComponent(BuildAssembler assembler, XPathNavigator configuration, bool isConceptual) : base(assembler, configuration) { try { _mathNumber = 1; _numberByPage = true; XPathNavigator navigator = configuration.SelectSingleNode("paths"); if (navigator == null) { throw new BuildComponentException( "The input/output paths, or <paths> tag, is required."); } _inputPath = navigator.GetAttribute("inputPath", String.Empty); if (String.IsNullOrEmpty(_inputPath)) { throw new BuildComponentException("The input path is required."); } _inputPath = Environment.ExpandEnvironmentVariables(_inputPath); _inputPath = Path.GetFullPath(_inputPath); // Delete the current input path...to empty the contents. try { if (Directory.Exists(_inputPath)) { Directory.Delete(_inputPath, true); } } catch (Exception ex) { this.WriteMessage(MessageLevel.Warn, ex); } // Create the input path... try { if (!Directory.Exists(_inputPath)) { Directory.CreateDirectory(_inputPath); } } catch (Exception ex) { this.WriteMessage(MessageLevel.Warn, ex); } _outputBasePath = navigator.GetAttribute("baseOutput", String.Empty); if (String.IsNullOrEmpty(_outputBasePath)) { throw new BuildComponentException("The base output path is required."); } _outputBasePath = Environment.ExpandEnvironmentVariables(_outputBasePath); _outputBasePath = Path.GetFullPath(_outputBasePath); _outputPath = navigator.GetAttribute("outputPath", String.Empty); if (String.IsNullOrEmpty(_outputPath)) { throw new BuildComponentException("The output path is required."); } _outputPath = Environment.ExpandEnvironmentVariables(_outputPath); _outputPath = Path.Combine(_outputBasePath, _outputPath); try { if (!Directory.Exists(_outputPath)) { Directory.CreateDirectory(_outputPath); } } catch (Exception ex) { this.WriteMessage(MessageLevel.Warn, ex); } //_linkPath = navigator.GetAttribute("link", String.Empty); //if (_linkPath[_linkPath.Length - 1] != '/') //{ // _linkPath = _linkPath + "/"; //} navigator = configuration.SelectSingleNode("numbering"); if (navigator != null) { string attribute = navigator.GetAttribute("show", String.Empty); if (String.IsNullOrEmpty(attribute) == false) { _numberShow = Convert.ToBoolean(attribute); } attribute = navigator.GetAttribute("byPage", String.Empty); if (String.IsNullOrEmpty(attribute) == false) { _numberByPage = Convert.ToBoolean(attribute); } attribute = navigator.GetAttribute("format", String.Empty); if (String.IsNullOrEmpty(attribute) == false) { _numberFormat = attribute; } attribute = navigator.GetAttribute("formatIncludesPage", String.Empty); if (String.IsNullOrEmpty(attribute) == false) { _numberIncludesPage = Convert.ToBoolean(attribute); } } if (String.IsNullOrEmpty(_numberFormat)) { if (_numberIncludesPage) { _numberFormat = "({0}.{1})"; } else { _numberFormat = "({0})"; } } XPathNodeIterator iterator = configuration.Select("formatter"); if (navigator == null) { throw new BuildComponentException( "At least a formatter is required to use this component."); } Type compType = this.GetType(); MessageWriter msgWriter = assembler.MessageWriter; foreach (XPathNavigator formatter in iterator) { string attribute = formatter.GetAttribute("format", String.Empty); if (String.IsNullOrEmpty(attribute)) { throw new BuildComponentException("The format tag is required."); } if (String.Equals(attribute, "latex", StringComparison.OrdinalIgnoreCase)) { if (_latexFormatter == null) { string latexType = formatter.GetAttribute("type", String.Empty); if (String.Equals(latexType, "MikTeX", StringComparison.OrdinalIgnoreCase)) { _latexFormatter = new MathMikTeXFormatter(compType, msgWriter, formatter); _latexFormatter.BeginUpdate(_inputPath, isConceptual); } else if (String.Equals(latexType, "MimeTeX", StringComparison.OrdinalIgnoreCase)) { _latexFormatter = new MathMimeTeXFormatter( compType, msgWriter, formatter); _latexFormatter.BeginUpdate(_inputPath, isConceptual); } } } } if (_latexFormatter != null) { _latexFormatter.Update(configuration); navigator = configuration.SelectSingleNode("naming"); if (navigator != null) { MathNamingMethod namingMethod = MathNamingMethod.Sequential; string attribute = navigator.GetAttribute("method", String.Empty); if (String.IsNullOrEmpty(attribute) == false) { namingMethod = (MathNamingMethod)Enum.Parse( typeof(MathNamingMethod), attribute, true); _latexFormatter.NamingMethod = namingMethod; attribute = navigator.GetAttribute("prefix", String.Empty); if (attribute != null) { _latexFormatter.NamingPrefix = attribute; } } } _latexFormatter.EndUpdate(); } // Check the availability of a LaTeX distribution... _latexPath = SearchExecutable("latex.exe"); _isLaTeXInstalled = (!String.IsNullOrEmpty(_latexPath) && File.Exists(_latexPath)); // Warn if no distribution is found... if (!_isLaTeXInstalled) { this.WriteMessage(MessageLevel.Warn, "There is no LaTeX installation found. Please installed the MikTeX (http://www.miktex.org/)."); } } catch (Exception ex) { this.WriteMessage(MessageLevel.Error, ex); } }
/// <summary> /// This reads and sets its state or attributes stored in a <c>XML</c> format /// with the given reader. /// </summary> /// <param name="reader"> /// The reader with which the <c>XML</c> attributes of this object are accessed. /// </param> /// <exception cref="ArgumentNullException"> /// If the <paramref name="reader"/> is <see langword="null"/>. /// </exception> public override void ReadXml(XmlReader reader) { BuildExceptions.NotNull(reader, "reader"); Debug.Assert(reader.NodeType == XmlNodeType.Element); if (reader.NodeType != XmlNodeType.Element) { return; } if (!String.Equals(reader.Name, TagName, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, String.Format( "The element name '{0}' does not match the expected '{1}'.", reader.Name, TagName)); return; } string tempText = reader.GetAttribute("name"); if (String.IsNullOrEmpty(tempText) || !String.Equals(tempText, ConfigurationName, StringComparison.OrdinalIgnoreCase)) { throw new BuildException(String.Format( "ReadXml: The current name '{0}' does not match the expected name '{1}'.", tempText, ConfigurationName)); } if (reader.IsEmptyElement) { return; } while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element) && String.Equals(reader.Name, "property", StringComparison.OrdinalIgnoreCase)) { switch (reader.GetAttribute("name").ToLower()) { case "enabled": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { this.Enabled = Convert.ToBoolean(tempText); } break; case "inlinemathsize": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _inlineSize = Convert.ToInt32(tempText); } break; case "inlinemathzoom": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _inlineZoom = Convert.ToInt32(tempText); } break; case "displayedmathsize": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _displayedSize = Convert.ToInt32(tempText); } break; case "displayedmathzoom": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _displayedZoom = Convert.ToInt32(tempText); } break; case "inputpath": _inputPath = reader.ReadString(); break; case "baseoutput": _baseOutput = reader.ReadString(); break; case "outputpath": _outputPath = reader.ReadString(); break; case "namingprefix": _namingPrefix = reader.ReadString(); break; case "namingmethod": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _namingMethod = (MathNamingMethod)Enum.Parse( typeof(MathNamingMethod), tempText, true); } break; case "numberingenabled": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _numEnabled = Convert.ToBoolean(tempText); } break; case "numberingbypage": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _numByPage = Convert.ToBoolean(tempText); } break; case "numberingformatincludespage": tempText = reader.ReadString(); if (!String.IsNullOrEmpty(tempText)) { _numFormatIncludesPage = Convert.ToBoolean(tempText); } break; case "numberingformat": _numFormat = reader.ReadString(); break; default: // Should normally not reach here... throw new NotImplementedException(reader.GetAttribute("name")); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (String.Equals(reader.Name, TagName, StringComparison.OrdinalIgnoreCase)) { break; } } } }