Package hlcd.exporter

Class LatexMatrixWriter

java.lang.Object
hlcd.exporter.LatexMatrixWriter

public class LatexMatrixWriter extends Object
Exports the generator matrix \(G\) of the code \(\mathsf{C}\) as a .tex file. Similar to CodeExporter, this will not automatically override the file if it already exists because it does use a timestamp.

The .tex file that will be generated assumes there exist a \(\LaTeX\) environment named optimalCodeMatrix. Here is a complete but minimal example showing the definition of optimalCodeMatrix:

\documentclass[12pt]{article}
 \usepackage{array}
 \usepackage{ifthen}

 \newcolumntype{:}{%
  !{\hspace{2.5pt}\vrule width 1pt\hspace{2.5pt}}
 }
 \newcommand{\nMinusK}[2]{\the\numexpr #1 - #2}
 \newcommand{\code}[1][]{%
  \ifthenelse{\equal{#1}{}}%
  {\ensuremath{[n, k, d]}}%
  {\ensuremath{[#1]}}%
 }
 \newenvironment{optimalCodeMatrix}[5][]
 {
 \begin{equation}
 \arraycolsep=3pt
 \ifx&#1&% optional argument has been passed
     \label{eq:#2_#3_#4_#5}
     #2_{{\code[#3, \, #4, \, #5]}_4} =%
 \else% no optional argument :(
     \label{eq:#2_#3_#4_#5_#1}
     #2^{#1}_{{\code[#3, \, #4, \, #5]}_4} =%
 \fi
 \left[
 \begin{array}{@{}*{#4}{c}:*{\nMinusK{#3}{#4}}{c}@{}}
 }
 {
 \end{array}
 \right]
 \end{equation}
 }

 \begin{document}
 \begin{optimalCodeMatrix}[]{G}{7}{4}{3}
        1 & 0 & 0 & 0 & 0 & 1 & 1       \\
        0 & 1 & 0 & 0 & 0 & 1 & \omega  \\
        0 & 0 & 1 & 0 & 1 & 0 & 1       \\
        0 & 0 & 0 & 1 & 1 & 0 & \omega  \\
 \end{optimalCodeMatrix}
 \end{document}

The above will render the following matrix:

\( G_{\left[ 7, \, 4, \, 3\right]_4} = \left[\begin{array}{cccc|ccc} 1 & 0 & 0 & 0 & 0 & 1 & 1 \\ 0 & 1 & 0 & 0 & 0 & 1 & \omega \\ 0 & 0 & 1 & 0 & 1 & 0 & 1 \\ 0 & 0 & 0 & 1 & 1 & 0 & \omega \\ \end{array}\right] \)

 //minimal example to execute this class:
 public static void main(String[] args) {
     System.out.println("Running LatexMatrixWriter...");
     String path = Paths.DEFAULT_PATH;
     byte n = 7;
     byte k = 4;
     byte d = 3;
     byte base = 4;
     boolean printPathToConsole = true;
     CodeParameters cp = new CodeParameters(n, k, d, base);
     CodeValidatorParameters cvp = new CodeValidatorParameters();
     CodeExporterParameters cep = new CodeExporterParameters();
     Code code = new Code(cp, cvp);
     code.startEngine();
     code.printGeneratorMatrix(true, Style.DECIMAL, true);
     DirectoryCreator dc = new DirectoryCreator( path, "LatexMatrixWriter");
     dc.createDirectory();
     LatexMatrixWriter lcw = new LatexMatrixWriter(
         dc,                        //directory creator
         code.getCodeParameters(),  //code parameters
         code.getGeneratorMatrix(), //generator matrix to write
         "G",                       //label of the generator matrix
         "&",                       //delimiter between matrix columns
         "0",                       //the id of the generator matrix
         true,                      //surround delimiter by space
         Style.QUATERNARY,          //the style of digits
         printPathToConsole         //should print path to console
     );
     lcw.writeMatrixAsLatex();
     System.out.println("LatexMatrixWriter completed.");
 }
Since:
1.8
Version:
1.0 (January 24th, 2022)
Author:
Maysara Al Jumaily
  • Constructor Details

    • LatexMatrixWriter

      public LatexMatrixWriter(DirectoryCreator dc, CodeParameters cp, Matrix matrix, String matrixLabel, String delimiter, String id, boolean spaceBetweenDelimiter, Style style, boolean printPathToConsole)
      Initializes the LaTeX matrix writer based on the parameters specified.
      Parameters:
      dc - the directory creator object to ensure the files are stored in the appropriate place
      cp - the code parameters (i.e., \(n\), \(k\), \(d\), \(base\), etc.)
      matrix - the generator matrix \(G\)
      matrixLabel - the generator matrix label (should be "G")
      delimiter - the delimiter used when .tex file is written (should be "&")
      id - The id that would be associated with the matrix. Used when multiple generator matrices of the same \(\left[n, \, k, \, d\right]_{base}\) code are generated. Should be "0" if only a single generator matrix is found.
      spaceBetweenDelimiter - Should there be a space between the delimiter used. Regardless of the value, this doesn't affect the output, it is there for aesthetic purposes
      style - should the .tex file write a matrix in binary, decimal or quaternary. For a binary code, this doesn't matter. For a quaternary code, a binary style will write the digits as \(00\), \(01\), \(10\) and \(11\). A decimal style will use \(0\), \(1\), \(2\) and \(3\). A quaternary style uses \(0\), \(1\), \(\omega\) and \(\overline{\omega}\). Lastly, the LaTeX style will write everything in \(\LaTeX\) syntax.
      printPathToConsole - should the file paths generated be printed to console
  • Method Details

    • writeMatrixAsLatex

      public void writeMatrixAsLatex()
      Writes the .tex to the directory passed in the constructor.