Git Product home page Git Product logo

hatex's Introduction

This repository has been moved to:

https://gitlab.com/daniel-casanueva/haskell/HaTeX

The HaTeX library

HaTeX is a Haskell library that implements the LaTeX syntax, plus some abstractions on top.

Check a list of usage examples in the Examples directory of the repository in GitHub. A good starting point is simple.hs. Run any example script executing the main function.

Installation notes

To install HaTeX, use cabal-install or stack.

To install with cabal, run:

$ cabal update
$ cabal install HaTeX

This will download and install the latest official release (recommended). If you want to try a newer version, use git to clone the code contained in this repository.

$ git clone https://github.com/Daniel-Diaz/HaTeX.git
$ cd HaTeX
$ cabal install

However, this is not recommended as it may include some bugs or oddities due to in-development features. Note that this package follows the Package Versioning Policy, so it is unlikely to suffer from API breakages if you follow it too when importing the library (assuming you are using the version in Hackage).

Current HaTeX versions

HaTeX on Hackage

HaTeX on Stackage

HaTeX on Stackage Nightly

HaTeX User's Guide

The HaTeX User's Guide lives here... and is also done in Haskell! It is free source and anybody can contribute to it. Doing so, you will help current and future users!

A downloadable version (not necessarily the latest version, but most likely) can be found here. To be sure that you are reading the last version, go to the github repository of the guide and follow instructions to build it. It is fairly easy.

Please note that the user's guide needs to be updated (contributions are more than welcome!).

Community and Contributions

There are many ways to get involved in the HaTeX project. Use the most comfortable way for you.

TODO list

  • Add more examples.
  • Add more documentation.
  • BibTeX support.

Related projects

  • haskintex: Tool to use Haskell (and, additionaly, the HaTeX library) within a LaTeX file.
  • TeX-my-math: Experimental library to ease the production of mathematical expressions using HaTeX.

hatex's People

Contributors

0xcm avatar alexfmpe avatar bgamari avatar coffeecup-winner avatar daniel-diaz avatar ddssff avatar dmcclean avatar finlay avatar jhedev avatar kommusoft avatar l3n41c avatar langston-barrett avatar leftaroundabout avatar nightra avatar romildo avatar rszczers avatar shimuuar avatar snoyberg avatar utdemir avatar ysangkok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hatex's Issues

Work on the Base.Command module documentation

Currently, the Base.Commands module lacks documentation for a bit more than a half of its bindings, and the description of some of them is quite vague. While it may be expected for the user of HaTeX to know some LaTeX, it would be more convenient if the information about the different commands can be found in-place, as in the rest of modules. The only difference is that this module is certainly bigger.

New test failure, GHC 7.6.3

I just received this failure from a separate Stackage build:

  Parser
    render . parse = id: FAIL
      *** Failed! Falsifiable (after 26 tests): 
      TeXEnv "LXGWR" [] (TeXRaw " nYrBLWpWf\\{\"T")
      Use --quickcheck-replay '25 513217224 1655838838' to reproduce.

1 out of 3 tests failed
Test suite hatex-test: FAIL
Test suite logged to: dist/test/HaTeX-3.11.0.1-hatex-test.log
0 of 1 test suites (0 of 1 test cases) passed.

QuickCheck the parser

To check that the parser is working properly once and for all we should write a QuickCheck test. The Arbitrary instance written by @toschoo here could be a starting point.

Remove TeXOp data constructor

This constructor is actually an special case of a TeXRaw between two other LaTeX expressions. Should we remove it?

Undefined functions in Num, Floating instances

Right now the Num and Floating instances for LaTeX in the AMSMath package contain errors for certain functions that aren't defined by AMSMath.

Would you accept a patch changing them to use AMSMath's \operatorname{ } command?

https://github.com/Daniel-Diaz/HaTeX/blob/master/Text/LaTeX/Packages/AMSMath.hs#L150

 -- Non-defined methods
 signum _ = error "Cannot use \"signum\" Num method with a LaTeX value."

would become as below, with similar functions for inverse hyperbolic trig functions from Floating.

 signum = (operatorname "sgn" <>)

-- Whether or not to expose this helper is up for debate.
operatorname :: LaTeXC l => l -> l
operatorname = comm1 "operatorname"

sgn is the name used in the wikipedia article and is in fairly wide use. arctanh etc seem uncontroversial. Obviously clients that are unhappy with it would be free to avoid using these functions as the documentation warns to do today.

Compile Time Error for HaTeX 3.17.0.0

I get the following compile time error when I try to install HaTeX 3.17.0.0 from Hackage:


[15 of 34] Compiling Text.LaTeX.Base.Parser ( Text/LaTeX/Base/Parser.hs, dist/build/Text/LaTeX/Base/Parser.o )

Text/LaTeX/Base/Parser.hs:364:32:
    No instance for (Stream Text Data.Functor.Identity.Identity Char)
      arising from a use of ‘char’
    In the first argument of ‘(*>)’, namely ‘char '.'’
    In the second argument of ‘(<$>)’, namely
      ‘(char '.' *> (some digit <?> "fraction"))’
    In the expression:
      foldr op 0.0 <$> (char '.' *> (some digit <?> "fraction"))

Text/LaTeX/Base/Parser.hs:375:18:
    No instance for (Stream Text Data.Functor.Identity.Identity Char)
      arising from a use of ‘char’
    In the second argument of ‘(<$)’, namely ‘char '-'’
    In the first argument of ‘(<|>)’, namely ‘negate <$ char '-'’
    In the first argument of ‘(<|>)’, namely
      ‘negate <$ char '-' <|> id <$ char '+'’
World file is already up to date.
cabal: Error: some packages failed to install:
HaTeX-3.17.0.0 failed during the building phase. The exception was:
ExitFailure 1

Support double-dollar math ($$...$$)

While the use of $$...$$ for math is discouraged in modern LaTeX, legacy documents still use it.

Currently, HaTeX parses $$ as TeXMath Dollar TeXEmpty.

Add a LaTeX pretty printer

It would be nice if the output of HaTeX were human readable, especially since that would allow gradual transition from LaTeX source to HaTeX source, at least for some of the document.

A renderPretty which adds line breaks and indentation would go a long way.

A more powerful, but more invasive, approach might be to use one of the existing pretty-printer combinator libraries (I'm partial to wl-pprint-extras) as the target for a render operation, with sensible defaults that the user can override.

x = render $ parse x

Hi Daniel,

I have tested your latest changes. Two small issues with Render:

  • you are adding spaces in comments
  • you are adding line breaks after ")" and "]"

I think render and parse should be inverse functions and we should not add text that wasn't there in the first place.

I have corrected this and I have removed the handling of displaymath etc. from the parser.

You might have a look at my test code, which includes a fair number of tex examples and an Arbitrary instance for the LaTeX type. Both can still be improved, but I think it's a good starting point.

What is the best way to use string literals containing Unicode and have it produce “safe” LaTeX code for it?

The IsString instance is pretty robust as far as ASCII is concerned, escaping characters that would be interpreted as control characters by LaTeX and instead producing the code that's needed for making the rendered output look like the original strings.

However, when a string contains Unicode, things aren't so clear-cut. While XeLaTeX has, unlike pdfLaTeX, proper support for UTF-8, it is still in my experience not given that Unicode input will be rendered properly. To be sure, I used to always escape e.g. German umlauts to the safe LaTeX form manually (like it's na\"ive to dismiss Mot\"orhead) when I still wrote LaTeX manually.

Now, that doesn't work in HaTeX, and since I have a couple of times found myself surprised by missing or inadequately substituted unicode characters because.

That seems like a problem we shouldn't be having. It would easy enough to add suitable rules to protectChar, like

diff --git a/Text/LaTeX/Base/Syntax.hs b/Text/LaTeX/Base/Syntax.hs
index 7801593..61ef225 100644
--- a/Text/LaTeX/Base/Syntax.hs
+++ b/Text/LaTeX/Base/Syntax.hs
@@ -134,6 +134,17 @@ protectChar '}'  = "\\}"
 protectChar '~'  = "\\~{}"
 protectChar '\\' = "\\textbackslash{}"
 protectChar '_'  = "\\_{}"
+protectChar 'ӓ'  = "\"a"
+protectChar 'ë'  = "\"e"
+protectChar 'ï'  = "\"i"
+protectChar 'ö'  = "\"o"
+protectChar 'ü'  = "\"u"
+protectChar 'Ä'  = "\"A"
+protectChar 'Ë'  = "\"E"
+protectChar 'Ï'  = "\"I"
+protectChar 'Ö'  = "\"O"
+protectChar 'Ü'  = "\"U"
+protectChar 'ß'  = "{\\ss}"
 protectChar x = [x]
 
 -- Syntax analysis

One might also wish to add accents etc..

But that might well be opening a can of worms. The question would immediately be, where do we end? I personally would be inclined to also add substitutions like $\mathbb{R}$, but that's clearly rather unsafe.

Is there a sensible option to offer multiple different IsString instances, in different modules that can be imported depending on what you need in your document?

Symbols not defined in a package

Is it OK to add \imath and \jmath to the Text.LaTeX.Packages.AMSMath module, in spite of the fact that they are technically defined somewhere else and you don't really need the package to use them?

If not, is there some other module where it would be appropriate to add them?

Numeric instances in AMSMath module

In order to make LaTeX and LaTeXT instances of the Floating numeric class, I wanted to use some functions exposed in the AMSMath module. Right now, numeric instances of LaTeX and LaTeXT are done in the Base module, and the idea is that modules under the Packages namespace make use of Base modules, but not the other way around.

I would like to move these instances to AMSMath and, once there, add a Floating instance for both types. This also would collect all the math related functions in the same module. Note that some methods (like / which uses the frac LaTeX command) require to be placed in a Math environment, and you need to import the AMSMath module to create such a environment.

Anybody find any drawback with it?

Keep in mind that this will be released in the next major version (3.5), so backward compatibility issues are not taken in account.

Documentation clarification

The intro to the guide states that HaTeX

provides functions to create, manipulate and parse LaTeX code

It's unclear from the guide, examples, and comments to the source code, however, whether the user should expect to be able to parse and manipulate a LaTeX code block. That is, having imported a well-formed LaTeX object, it is possible to render it and to detect some features

> lookForCommand "hline" input

[[],[],[]]

but functions to change elements in-block appear to be either missing or too obvious to require any indication for the intended audience. (In personal terms, as a newcomer to Haskell, I can't tell whether I'm just missing something blindingly obvious or if what would be required is to build up the functions to do this through finding ways of recombining the existing pieces.)

To give a concrete example of what I am trying to do

{-# LANGUAGE OverloadedStrings #-}

module Himport where

import Text.LaTeX
import Text.LaTeX.Base.Parser
import Text.LaTeX.Base.Syntax
import Text.LaTeX.Base.Render
import Data.Either
import Data.Maybe (fromJust)

main = do 
  obj <- parseLaTeXFile "tester.Rmd"
  return obj

fromRight           :: Either a b -> b
fromRight (Left _)  = error "fromRight: Argument takes form 'Left _'" 
fromRight (Right x) = x

getTable :: LaTeX -> Maybe LaTeX
getTable l =
  case lookForEnv "table" l of
    ((_,b):_) -> Just b
    _ -> Nothing

I import this into the repl and create a Either ParseError LaTeX object

: obj <- main

and extract the LaTeX block with

: let input = fromRight obj

This gives me

     TeXSeq (TeXComment " latex table generated in R 3.2.1 by xtable 1.7-4 package") (TeXSeq (TeXComment " Mon Nov  9 21:01:01 2015") (TeXSeq (TeXEnv "table" [OptArg (TeXRaw "ht")] (TeXSeq (TeXRaw "\n") (TeXSeq (TeXCommS "centering") (TeXSeq (TeXRaw "\n") (TeXSeq (TeXEnv "tabular" [FixArg (TeXRaw "rrrrr")] (TeXSeq (TeXRaw "\n  ") (TeXSeq (TeXCommS "hline") (TeXSeq (TeXRaw "\n & Disputed & Firearm & Knife & No ") (TeXSeq (TeXLineBreak Nothing False) (TeXSeq (TeXRaw " \n  ") (TeXSeq (TeXCommS "hline") (TeXSeq (TeXRaw "\nDeath in custody & 0.00 & 0.00 & 0.00 & 3.86 ") (TeXSeq (TeXLineBreak Nothing False) (TeXSeq (TeXRaw " \n  Gunshot & 0.30 & 47.92 & 14.24 & 9.50 ") (TeXSeq (TeXLineBreak Nothing False) (TeXSeq (TeXRaw " \n  Struck by vehicle & 0.00 & 0.15 & 0.00 & 3.26 ") (TeXSeq (TeXLineBreak Nothing False) (TeXSeq (TeXRaw " \n  Taser & 0.00 & 0.00 & 0.15 & 4.60 ") (TeXSeq (TeXLineBreak Nothing False) (TeXSeq (TeXRaw " \n  Unknown & 0.00 & 0.00 & 0.00 & 0.45 ") (TeXSeq (TeXLineBreak Nothing False) (TeXSeq (TeXRaw " \n  Sum & 0.30 & 48.07 & 14.39 & 21.66 ") (TeXSeq (TeXLineBreak Nothing False) (TeXSeq (TeXRaw " \n   ") (TeXSeq (TeXCommS "hline") (TeXRaw "\n")))))))))))))))))))))) (TeXSeq (TeXRaw "\n") (TeXSeq (TeXComm "caption" [FixArg (TeXRaw "Causes of 674 civilian deaths by type of weapon carried by civilian, part 1")]) (TeXSeq (TeXRaw " \n") (TeXSeq (TeXComm "label" [FixArg (TeXRaw "2")]) (TeXRaw "\n")))))))))) (TeXRaw "\n")))

which is where I'm stuck. Ultimately, I wish to delete the comments and label commands, insert a different line after each of the first two hlines, add text to the beginning of the table line, change the tabular justification of the first column, insert some text at the beginning of a specific row, change capitalization and convert "0.00" to "." These are all things I can do to strings, already, using regex, but that seem a clumsy translation from the imperative world.

If the functions are there and non-obvious, a hint would help or if they are not included a mention that the flow all goes into a LaTeX block and from there it can only be rendered, if any further changes or necessary the block must be reassembled from its pieces.

Very comprehensive package that should become a backbone for lhs. Thanks.

Should we try to get HaTeX more compatible with lenses?

Lenses are getting increasingly ubiquitous in the Haskell world. (I consider this a good thing.) In virtually everything I'm doing now there's at least one library involved that uses them.

It's generally not a problem to combine libraries using lenses with ones that don't; with HaTeX in particular there's one rather trivial issue that it defines (&) as the column seperation operator, while lens uses (&) as flipped function-application. It's easy to resolve this with qualified imports, but still a bit tedious. Should we rename it to (&:), keeping with the scheme already used for several other operators in HaTeX ((=:), (!:), (%:)...)?

While on the subject, would it be worthwhile to use lenses in HaTeX itself? (Perhaps the answer is just no, since there aren't many record types – are any exposed at all?)

\author command is obsolete, implement \authorinfo

LaTeX gives the error

LaTeX Error: The \author command is obsolete; use \authorinfo.

As far as I can see, \authorinfo is not implemented. Should this be included in the HaTeX library?

If so, this is a simple implementation which I should get around to soon, just creating this PR to remind myself.

Add examples of how to draw linked nodes with TikZ

It is not clear to me how to draw linked nodes using the Text.LaTeX.Packages.TikZ. Please, add examples of it.

For instance, how to translate the following LaTeX code to HaTeX?

\documentclass[convert]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[node distance=3cm]
  \node[rectangle,draw](a){First Node};
  \node[][right of=a](b){Second\\Node};
  \node[circle,draw,fill=blue!30][right of=b](c){Third\\Node}
    edge [->, bend right=45] node[auto,swap]{$x$}(a);
\end{tikzpicture}

\end{document}

The typeset document gives:
tikz-linked-nodes

Proposal: Remove TeXSeq and TeXEmpty

Is there a compelling reason for the TeXSeq and TeXEmpty constructors vs. something like

newtype LaTeX = LaTeX [Block]
data Block =
   TeXRaw Text
 | TeXComm String [TeXArg]
 | TeXCommS String
 | TeXEnv String [TeXArg] LaTeX
 | TeXMath MathType LaTeX
 | TeXLineBreak (Maybe Measure) Bool
 | TeXBraces LaTeX
 | TeXComment Text
   deriving (Eq,Show,Typeable)

The advantage of this over the current type is that it seems to better reflect the meaning of a LaTeX document. Specifically, it removes a lot of terms which denote the same TeX expression but have different structures. E.g., currently

TeXSeq (TexSeq a b) c /= TeXSeq a (TeXSeq b c)

and

TeXSeq TeXEmpty TeXEmpty /= TeXEmpty

but these distinctions are not expressible in the type I propose. I suppose with the current scheme one gets O(1) concatenation, although the cost of converting the tree into a list is likely to be paid during conversion to text, so it's unclear if this is an advantage.

My personal reason for wanting to make this change is to make it easy to parse a LaTeX document using parsec. Currently I have to implement a nontrivial stream instance which is only correct assuming the document has the form

TeXSeq a1 (TeXSeq a2 .(TeXSeq a3 ...) ... )

with the constructor of ai not equal to TeXSeq.
This assumption holds when using output from the library's parser, but it would be nice if the types forced this condition to hold.

Yesod-like widgets

One of the biggest frustrations I have with LaTeX is modularity.
It is tedious to prepare a document that can be compiled with different classes.
It is tedious to create a portable tikz figure because of the packages needed to draw it.
These problems are very similar to the ones encountered in web development.

Yesod has a clean solution for that problem: widgets (http://www.yesodweb.com/book/widgets)
It would be interesting to have a similar concept for HaTeX

These widgets would help with the aforementioned problems as well as for package dependencies.
You would not have to list the packages you need in order, this information could be encoded in HaTeX.

Unhappy with Attoparsec

While Attoparsec is very efficient and allows incremental parsing, we are losing a nice feature: good error reports. Most LaTeX files are written by hand, not machines. And they are usually somehow large. If there is a mistake somewhere, it will take too much time to find it with an attoparsec parser. Therefore, I am unhappy with attoparsec. In any case, it is not that LaTeX files are big enough to make performance so critical. Should we port the parser to other library with better error reporting?

Failure to parse simple newenvironment definitions

Parsing fails when there are newenviroment definitions in the header that have \begin{...} in the preamble, i.e. parsing

\documentclass{article}

\newenvironment{foo}{\begin{center}}{\end{center}}

\begin{document}

\end{document}

fails with the error "Failed reading: satisfy" and it fails reading \begin.

Revision of attoparsec dependency

Currently, there is no upper no lower bound in attoparsec dependency. I am not sure that we can build the parser in all previous versions of attoparsec, so a test should be made to determine an interval (ending at 0.11?) within is possible to build HaTeX.

Release

Would you mind releasing a new version to Hackage? I'd like to use the Semigroup instance for LaTeX that was added in January.

Test suite failure with GHC 7.4.2

Got this while running a Stackage build:

[1 of 1] Compiling Main             ( test/Main.hs, dist/build/matrix-test/matrix-test-tmp/Main.o )
Linking dist/build/matrix-test/matrix-test ...
Building HaTeX-3.11.0.0...
Preprocessing library HaTeX-3.11.0.0...
In-place registering HaTeX-3.11.0.0...
Preprocessing test suite 'matrix-test' for HaTeX-3.11.0.0...
Linking dist/build/matrix-test/matrix-test ...
Running 1 test suites...
Test suite matrix-test: RUNNING...
HaTeX
  LaTeX
    LaTeX mempty:        OK
      +++ OK, passed 100 tests.
    LaTeX mappend:       OK
      +++ OK, passed 100 tests.
  Parser
    render . parse = id: FAIL
      *** Failed! Falsifiable (after 46 tests): 
      TeXSeq (TeXComm "IEelCrT" [FixArg (TeXMath Parentheses (TeXRaw "A\\$quem!-@tx+kp?cr>")),MSymArg [TeXEnv "ZFRx" [OptArg (TeXMath Dollar (TeXRaw "Ugsr\\%Wh<e"))] (TeXMath Square (TeXMath Parentheses (TeXComment "\\$"))),TeXEnv "OhRiiDIdtT" [FixArg TeXEmpty,FixArg (TeXLineBreak (Just (Pt 15.071749328588327)) True),OptArg (TeXRaw "bznR!@\\{iE(Vg(LC"),MOptArg [TeXRaw "\"\"wY(UQCJxVv<'\\^{}",TeXRaw "lKBuy'\\&*v/)nd\\_{}efgil",TeXComment "]tdiWlhL",TeXRaw "Z'SG;P"]] (TeXRaw ";Dp"),TeXRaw ":\"QD*\\%Soe.ktZBCpo;",TeXCommS "bWwAWXCxS"],MSymArg [TeXRaw "C)ok)L<m]",TeXRaw "r",TeXEnv "EWZr" [SymArg (TeXRaw "G>!sXfr\\$L)]okfth?R"),MSymArg [TeXMath Dollar (TeXMath Parentheses (TeXMath Parentheses (TeXBraces (TeXRaw "\\textbackslash{})+a")))),TeXRaw "\"!me\\#"],MOptArg [TeXLineBreak (Just (Em 20.586791879992205)) False,TeXLineBreak (Just (Mm (-60.036266626268834))) False,TeXLineBreak (Just (Mm 15.751990081354155)) True,TeXRaw "cy\"\nFsl,bd-d\\%HLs/"],SymArg (TeXLineBreak (Just (Mm 38.6319352502519)) False),FixArg (TeXComment "GF\\_{}?\nxikG")] TeXEmpty],FixArg (TeXRaw "X;;")]) TeXEmpty
      Use --quickcheck-replay '45 1632621174 1655838818' to reproduce.

1 out of 3 tests failed
Test suite matrix-test: FAIL
Test suite logged to: dist/test/HaTeX-3.11.0.0-matrix-test.log
0 of 1 test suites (0 of 1 test cases) passed.

cannot compile with ghc 7.10 RC 3

Building HaTeX-3.16.0.0...

[15 of 33] Compiling Text.LaTeX.Base.Parser ( Text/LaTeX/Base/Parser.hs, dist/build/Text/LaTeX/Base/Parser.o )

Text/LaTeX/Base/Parser.hs:93:16:
    No instance for (Foldable t0) arising from a use of ‘elem’
    The type variable ‘t0’ is ambiguous

Exception in very simple code and violation of monoid law

Here is example:

{-# LANGUAGE OverloadedStrings #-}
import Text.LaTeX
import Data.Functor.Identity

go = runIdentity $ runLaTeXT $ raw "TEXT"

Here is what I get in GHCi

*Main> go
(*** Exception: liftListL

Another issue which I think is related to this is violation of monoid law by LaTeXT.

instance Monad m => Monoid (LaTeXT m a) where
 mempty = return undefined
 mappend = (>>)

Expression x <> mempty discard whatever value is kept inside of x but it should be equal to x. I believe that only real way to fix this is to add Monoid a contraint and change definition to.

instance (Monad m, Monoid a) => Monoid (LaTeXT m a) where
 mempty = return mempty
 mappend = liftM2 mappend

It shouldn't be too onerous since () is instance of monoid

HaTeX fails to parse when `$` not used for math mode

HaTeX parses dollars signs as math mode, which is fine most of the time. But they can also be used in environments where they don't refer to math mode, and when they are, HaTeX will return Nothing rather than a syntax tree for the file.

For example:

\begin{lstlisting}
$ ls
$ cd directory
$ emacs file
\end{lstlisting}

or


\begin{minted}{haskell}
(+) <$> (Just 2) <*> (Just 3)
\end{minted}

The problem is that it expects $ to be a part of the syntax tree even though it's just a symbol. Any ideas how to address this edge case, either by changing how HaTeX parses or by changing something in the LaTeX file (without getting rid of the dollar sign entirely)?

pmatrix

If` I had a matrix like:
( "L" "M_R" )
( "M_R" "L_R" )

lMatrix =[["L","M_R"],["M_R","L_R"]]
lMatrix2 :: Monad m => LaTeXT_ m
lMatrix2= pmatrix Nothing $ (fromLists lMatrix)

how could I get this to latex without it inserting {} between spaces.
so this is what i'm getting;

\begin{pmatrix}L&M_{}R\M_{}R&L_{}R\end{pmatrix}

and this is what I want

\begin{pmatrix}L&M_R\M_R&L_R\\end{pmatrix}.

Using macros inside matrix

Hi, I want to get this latex code:

\begin{pmatrix}
  \text{\ensuremath{*}\ensuremath{p}\ensuremath{p}} \\
  \text{\ensuremath{*}\ensuremath{p}\ensuremath{*}} \\
  \text{\ensuremath{p}\ensuremath{*}\ensuremath{p}} \\
  \text{\ensuremath{p}\ensuremath{p}\ensuremath{*}} \\
  \text{\ensuremath{p}\ensuremath{p}\ensuremath{p}} \\
\end{pmatrix}

from this haskell list:

table :: [[Text]]
table = [["*pp"],["*p*"],["p*p"],["pp*"],["ppp"]]

Provide a way of converting TeXComm to TeXCommS throughout document

I'm imagining a function with like

unprotect :: Set String -> LaTeX -> LaTeX

or even

unprotect :: String -> LaTeX -> LaTeX

that traverses the tree and performs the conversion.

I was motivated to ask for this after noticing that the AMSMath commands use comm0 instead of commS. I assume there is a reason for that.

HaTeX is not typesafe

Well, honestly I am a bit disappointed with HaTeX. The idea of a typesafe DSL for generating LaTeX code seems great. But HaTeX is not typesafe.

Type-safety is all about preventing things from going wrong "at runtime". For HaTeX, "runtime" actually means: "when pdflatex processes the generated LaTeX code". But in HaTeX, nothing prevents you from doing stupid things like inserting an \hline outside a table environment.

Adding proper type-safety to HaTeX would probably bring a lot of complications, but I think it's actually needed if HaTeX aims to be a LaTeX generator one can trust.

Regards

HaTeX-3.16.0.0 can't compile its test suite

Citing from http://hydra.cryp.to/build/650375/log/raw:

Preprocessing test suite 'hatex-test' for HaTeX-3.16.0.0...
[1 of 1] Compiling Main             ( test/Main.hs, dist/build/hatex-test/hatex-test-tmp/Main.dyn_o )

test/Main.hs:8:10:
    Duplicate instance declarations:
      instance Eq ParseError -- Defined at test/Main.hs:8:10
      instance Eq ParseError
        -- Defined in ‘parsec-3.1.9:Text.Parsec.Error’

Printing symbols in a matrix

Hi, how can I print a matrix with symbols?

I'm using this code:

import Text.LaTeX
import Text.LaTeX.Base.Pretty
import Text.LaTeX.Packages.AMSMath
import Data.Matrix

table = [["a","","","",""],["","b","","",""],["","","c","","d"],["","","","a",""],["","","d","","e"]]

matrices :: Monad m => LaTeXT_ m
matrices = pmatrix Nothing $ (fromLists table)

main :: IO ()
main = putStrLn (execLaTeXT matrices >>= prettyLaTeX)

and I'm getting:

\begin{pmatrix}
    \left[ `a`\right] &\left[ \right] &\left[ \right]
    &\left[ \right] &\left[ \right] \\\left[ \right] &\left[
    `b`\right] &\left[ \right] &\left[ \right] &\left[
    \right] \\\left[ \right] &\left[ \right] &\left[
    `c`\right] &\left[ \right] &\left[ `d`\right] \\\left[
    \right] &\left[ \right] &\left[ \right] &\left[
    `a`\right] &\left[ \right] \\\left[ \right] &\left[
    \right] &\left[ `d`\right] &\left[ \right] &\left[
    `e`\right] \\
\end{pmatrix} 

But what I want is:

\begin{pmatrix}
  a &  &  &  &  \\
   & b &  &  &  \\
   &  & c &  & d \\
   &  &  & a &  \\
   &  & d &  & e \\
\end{pmatrix}

Space leaks with parsing right-open intervals

Following program causes a space leak:

{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Attoparsec.Text
import Text.LaTeX.Base.Parser

main :: IO ()
main = print $ parseOnly latexParser "$A \\cap [j_n, \\omega)$"

But A \cap [j_n, \omega) is valid latex code fragment. It seems that [j_n, \omega) is interpreted as an optional argument for \cap, which is the nullary latex command.

Type of ParColumnBot and the likes

I'm trying to create a fixed width table and struggle with the "ParColumnBot LaTeX" value constructor.
If I'm correct, the only viable argument is a Measure, so shouldn't its signature be
"ParColumnBot Measure".

If I'm mistaken, what's the right way to create an fixed width column?

Type size commands are not protected.

Hi, Daniel:
I am quite happy with HaTeX and I have used it in a couple of small projects. However, I have found a minor annoyance, the commands that change type size are not protected by braces, so they apply not only to their parameter but to the rest of the environment in which they are defined. I expected small "some text" to affect only to "some text", but it affects from the point of application onwards since the generated code is "\small{some text}" instead of "{\small some text}".

Regards,
Juan Miguel

Semigroup instance for LaTeX

I use ClassyPrelude, which exports (<>) from Semigroup, rather than from Monoid. As such, when using HaTeX, I have to use some import trickery:

import ClassyPrelude hiding ((<>))
import Text.LaTeX ((<>))

It would be much cleaner to just have a Semigroup LaTeX instance in this library. While this may sound like a me problem, there are some pretty good reasons to use Semigroups.

Since Semigroup is a superclass of Monoid, this would be a very easy two-line addition, and I'm happy to make a pull request:

instance Semigroup LaTeX where
  (<>) = mappend

For more information about Semigroups (if you're not familiar), here is a blog post: http://philipnilsson.github.io/Badness10k/posts/2016-07-14-functional-patterns-semigroup.html

Thoughts?

Num instance of LaTeXT was dropped in version 3.3

I just realized that the Num instance for LaTeXT has been dropped accidentally in version 3.3, because the Text.LaTeX.Base.Monad module was deleted with it. It must be done again in the Text.LaTeX.Base module.

latex prettyprinter produces blank lines where none are allowed

see this ghci session:

import Text.LaTeX.Base.Texy
import Text.LaTeX.Packages.AMSMath
import Text.LaTeX.Base.Pretty

putStrLn $ prettyLaTeX $ align_ [   texy ( 1   )]
putStrLn $ prettyLaTeX $ align_ [   texy ( 1,2 )]

which gives

\begin{align*}
    1
\end{align*}

\begin{align*}
    \left(
    1,2\right)

\end{align*}

where the first is OK, the second is not.

I really do need the prettyprinter because I want to copy-paste the latex code into a paper,
and possibly edit it - so I need it to be human-readable.

HaTeX-meta fails

metahatex fails with latest git and produces rather unhelpful error message:

$ metahatex 
metahatex: Ambiguous infix expression

This is due to updates to Parser.hs file.

TeXCommS should be made safer (particularly in render)

The case of render that deals with TeXSeq could (and I think should) check that a valid identifier character does not follow a TeXCommS. In particular, something like:

render (TeXSeq l1@(TeXCommS _) l2) = let r2 = render l2 in
  render l1 <> (case uncons r2 of {Just (c,_) | isAlpha c -> " "; _ -> ""}) <> r2
render (TeXSeq l1 l2) = render l1 <> render l2

How do lookForCommand and lookForEnv work?

I've tried to use lookForCommand and lookForEnv in the ways that seem most intuitive based on their descriptions, but they always seem to return an empty list. Moreover, I can't find tests in this codebase for these functions to use as examples. Here's what I've tried:

*Main Text.LaTeX.Base.Syntax Text.LaTeX> lookForCommand "author" (raw "\\author{Me}")
[]
*Main Text.LaTeX.Base.Syntax Text.LaTeX> lookForEnv "env" (raw "\\begin{env}env\\end{env}")
[]

The expected behavior is that these functions find the respective commands and environments, along with their arguments.

Can you help me understand what I've missed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.