Skip to content

Commit

Permalink
Improved display of strings; (4) of #1646
Browse files Browse the repository at this point in the history
  • Loading branch information
samm82 committed Jun 28, 2019
1 parent bd48017 commit 88119e4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion code/drasil-printers/Language/Drasil/HTML/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ uSymb (L.US ls) = formatu t b
pExpr :: Expr -> Doc
pExpr (Dbl d) = text $ showEFloat Nothing d ""
pExpr (Int i) = text $ show i
pExpr (Str s) = text s
pExpr (Str s) = text $ """ ++ s ++ """

This comment has been minimized.

Copy link
@JacquesCarette

JacquesCarette Jun 29, 2019

Owner

If there isn't already a combinator for doing this, there should be. Inlining things like this is not good.

This comment has been minimized.

Copy link
@samm82

samm82 Jul 2, 2019

Author Collaborator

Fixed in 8d99fe2

pExpr (Div a b) = fraction (pExpr a) (pExpr b)
pExpr (Case ps) = cases ps pExpr
pExpr (Mtx a) = text "<table class=\"matrix\">\n" <> pMatrix a <> text "</table>"
Expand Down
40 changes: 20 additions & 20 deletions code/drasil-printers/Language/Drasil/TeX/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,26 @@ data OpenClose = Open | Close
-----------------------------------------------------------------
-- (Since this is all implicitly in Math, leave it as String for now)
pExpr :: Expr -> String
pExpr (Dbl d) = showEFloat Nothing d ""
pExpr (Int i) = show i
pExpr (Str s) = s -- FIXME this is probably the wrong way to print strings
pExpr (Div n d) = "\\frac{" ++ pExpr n ++ "}{" ++ pExpr d ++"}"
pExpr (Case ps) = "\\begin{cases}\n" ++ cases ps ++ "\n\\end{cases}"
pExpr (Mtx a) = "\\begin{bmatrix}\n" ++ pMatrix a ++ "\n\\end{bmatrix}"
pExpr (Row [x]) = brace $ pExpr x -- a bit of a hack...
pExpr (Row l) = concatMap pExpr l
pExpr (Ident s) = s
pExpr (Spec s) = unPL $ L.special s
--pExpr (Gr g) = unPL $ greek g
pExpr (Sub e) = "_" ++ brace (pExpr e)
pExpr (Sup e) = "^" ++ brace (pExpr e)
pExpr (Over Hat s) = "\\hat{" ++ pExpr s ++ "}"
pExpr (MO o) = pOps o
pExpr (Fenced l r m) = fence Open l ++ pExpr m ++ fence Close r
pExpr (Font Bold e) = "\\mathbf{" ++ pExpr e ++ "}"
pExpr (Font Emph e) = pExpr e -- Emph is ignored here because we're in Math mode
pExpr (Spc Thin) = "\\,"
pExpr (Sqrt e) = "\\sqrt{" ++ pExpr e ++ "}"
pExpr (Dbl d) = showEFloat Nothing d ""
pExpr (Int i) = show i
pExpr (Str s) = "\\text{``" ++ s ++ "\"}"

This comment has been minimized.

Copy link
@JacquesCarette

JacquesCarette Jun 29, 2019

Owner

This is a 'mode change'. for consistency, the machinery in the printer to deal with mode changes should be used.

This comment has been minimized.

Copy link
@samm82

samm82 Jul 2, 2019

Author Collaborator

I'm not sure what you mean by this 😕

This comment has been minimized.

Copy link
@JacquesCarette

JacquesCarette Jul 9, 2019

Owner

That's because this mode-change functionality is only available in the LaTeX pretty-printer!

This comment has been minimized.

Copy link
@JacquesCarette

JacquesCarette Jul 9, 2019

Owner

I mean toMath and toText.

This comment has been minimized.

Copy link
@samm82

samm82 Jul 9, 2019

Author Collaborator

I'm pretty sure this is desired - the \text{``x"} in LaTeX is for printing ``x" as "x" in a math block, explicitly without switching to math mode. @smiths Feel free to correct me on this.

This comment has been minimized.

Copy link
@samm82

samm82 Jul 9, 2019

Author Collaborator

Also, the type of toText is toText :: D -> D, and in this case, we want a String.

This comment has been minimized.

Copy link
@JacquesCarette

JacquesCarette Jul 10, 2019

Owner

You are correct that in the output latex, you do want a \text. The whole point is that for \text to make sense, you need to be in math mode, and you're switching to printing text, i.e. text mode. So the right way to do this is to use toText.

The pre-condition that made this routine correct (that pExpr will always be in Math Mode) is false because Expr has a Str case. The comment on that line already said so! Thus pExpr should no longer output a String but rather a D. That is the correct way to fix this.

This comment has been minimized.

Copy link
@samm82

samm82 Jul 10, 2019

Author Collaborator

I'm still not entirely convinced that's the best way to do this. The string case isn't for printing text, it's for printing strings as a mathematical concept. For example, we could check to see if x = "foobar". The quotes are explicitly added around whatever string is contained in the Spec, and it shouldn't be italicized, hence the use of text. All Spec is printed through spec, which has the pattern:

spec (E ex) = toMath $ pure $ text $ pExpr ex

so all cases of this pattern are in math mode. Also, sorry for any confusion; before I said:

the \text{``x"} in LaTeX is for printing x as "x" in a math block, explicitly without switching to math mode.

What I meant was:

the \text{``x"} in LaTeX is for printing x as "x" in a math block, explicitly without switching to text mode.

This comment has been minimized.

Copy link
@JacquesCarette

JacquesCarette Jul 11, 2019

Owner

The use of \text is correct, and was not the issue here. The only question is whether the toText combinator should be used to produce that \text; the quotes still need to be generated here (but should likely be done via doublequotes and [I think] around). We know that s is a String, so there's no worry about compositionality, etc.

This comment has been minimized.

Copy link
@samm82

samm82 Jul 11, 2019

Author Collaborator

Sorry for the confusion - I miss understood what toText did 😕

pExpr (Div n d) = "\\frac{" ++ pExpr n ++ "}{" ++ pExpr d ++"}"
pExpr (Case ps) = "\\begin{cases}\n" ++ cases ps ++ "\n\\end{cases}"
pExpr (Mtx a) = "\\begin{bmatrix}\n" ++ pMatrix a ++ "\n\\end{bmatrix}"
pExpr (Row [x]) = brace $ pExpr x -- a bit of a hack...
pExpr (Row l) = concatMap pExpr l
pExpr (Ident s) = s
pExpr (Spec s) = unPL $ L.special s
--pExpr (Gr g) = unPL $ greek g
pExpr (Sub e) = "_" ++ brace (pExpr e)
pExpr (Sup e) = "^" ++ brace (pExpr e)
pExpr (Over Hat s) = "\\hat{" ++ pExpr s ++ "}"
pExpr (MO o) = pOps o
pExpr (Fenced l r m) = fence Open l ++ pExpr m ++ fence Close r
pExpr (Font Bold e) = "\\mathbf{" ++ pExpr e ++ "}"
pExpr (Font Emph e) = pExpr e -- Emph is ignored here because we're in Math mode
pExpr (Spc Thin) = "\\,"
pExpr (Sqrt e) = "\\sqrt{" ++ pExpr e ++ "}"

pOps :: Ops -> String
pOps IsIn = "\\in{}"
Expand Down
12 changes: 6 additions & 6 deletions code/stable/glassbr/SRS/GlassBR_SRS.tex
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ \subsubsection{Data Definitions}
Units & Unitless
\\ \midrule \\
Equation & \begin{displaymath}
J=interpZ\left(SDF.txt,AR,\hat{q}\right)
J=interpZ\left(\text{``SDF.txt"},AR,\hat{q}\right)
\end{displaymath}
\\ \midrule \\
Description & \begin{symbDescription}
Expand Down Expand Up @@ -619,9 +619,9 @@ \subsubsection{Data Definitions}
\\ \midrule \\
Equation & \begin{displaymath}
GTF=\begin{cases}
1, & g=AN\\
4, & g=FT\\
2, & g=HS
1, & g=\text{``AN"}\\
4, & g=\text{``FT"}\\
2, & g=\text{``HS"}
\end{cases}
\end{displaymath}
\\ \midrule \\
Expand Down Expand Up @@ -694,7 +694,7 @@ \subsubsection{Data Definitions}
Units & Unitless
\\ \midrule \\
Equation & \begin{displaymath}
{\hat{q}_{tol}}=interpY\left(SDF.txt,AR,{J_{tol}}\right)
{\hat{q}_{tol}}=interpY\left(\text{``SDF.txt"},AR,{J_{tol}}\right)
\end{displaymath}
\\ \midrule \\
Description & \begin{symbDescription}
Expand Down Expand Up @@ -923,7 +923,7 @@ \subsubsection{Data Definitions}
Units & Pa
\\ \midrule \\
Equation & \begin{displaymath}
q=interpY\left(TSD.txt,SD,{w_{TNT}}\right)
q=interpY\left(\text{``TSD.txt"},SD,{w_{TNT}}\right)
\end{displaymath}
\\ \midrule \\
Description & \begin{symbDescription}
Expand Down
12 changes: 6 additions & 6 deletions code/stable/glassbr/Website/GlassBR_SRS.html
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ <h3>Data Definitions</h3>
<th>Equation</th>
<td>
<div class="equation">
<em>J = interpZ(SDF.txt,AR,q&#770;)</em>
<em>J = interpZ(&quot;SDF.txt&quot;,AR,q&#770;)</em>
</div>
</td>
</tr>
Expand Down Expand Up @@ -1266,9 +1266,9 @@ <h3>Data Definitions</h3>
<div class="equation">
<em>GTF = <span class="casebr">{</span>
<div class="cases">
<span>1 , <span class="case">g = AN</span></span>
<span>4 , <span class="case">g = FT</span></span>
<span>2 , <span class="case">g = HS</span></span>
<span>1 , <span class="case">g = &quot;AN&quot;</span></span>
<span>4 , <span class="case">g = &quot;FT&quot;</span></span>
<span>2 , <span class="case">g = &quot;HS&quot;</span></span>
</div></em>
</div>
</td>
Expand Down Expand Up @@ -1402,7 +1402,7 @@ <h3>Data Definitions</h3>
<th>Equation</th>
<td>
<div class="equation">
<em>q&#770;<sub>tol</sub> = interpY(SDF.txt,AR,J<sub>tol</sub>)</em>
<em>q&#770;<sub>tol</sub> = interpY(&quot;SDF.txt&quot;,AR,J<sub>tol</sub>)</em>
</div>
</td>
</tr>
Expand Down Expand Up @@ -1821,7 +1821,7 @@ <h3>Data Definitions</h3>
<th>Equation</th>
<td>
<div class="equation">
<em>q = interpY(TSD.txt,SD,w<sub>TNT</sub>)</em>
<em>q = interpY(&quot;TSD.txt&quot;,SD,w<sub>TNT</sub>)</em>
</div>
</td>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions code/stable/projectile/SRS/Projectile_SRS.tex
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ \subsubsection{Instance Models}
\\ \midrule \\
Equation & \begin{displaymath}
s=\begin{cases}
The target was hit., & |\frac{{d_{offset}}}{{p_{target}}}|<ε\\
The projectile fell short., & {d_{offset}}<0\\
The projectile went long., & {d_{offset}}>0
\text{``The target was hit."}, & |\frac{{d_{offset}}}{{p_{target}}}|<ε\\
\text{``The projectile fell short."}, & {d_{offset}}<0\\
\text{``The projectile went long."}, & {d_{offset}}>0
\end{cases}
\end{displaymath}
\\ \midrule \\
Expand Down
32 changes: 16 additions & 16 deletions code/stable/projectile/Website/Projectile_SRS.html
Original file line number Diff line number Diff line change
Expand Up @@ -1541,26 +1541,26 @@ <h3>Instance Models</h3>
<em>s = <span class="casebr">{</span>
<div class="cases">
<span>
The target was hit. , <span class="case">
|<div class="fraction">
<span class="fup">
d<sub>offset</sub>
</span>
<span class="fdn">
p<sub>target</sub>
</span>
</div>|&thinsp;&lt;&thinsp;ε
</span>
&quot;The target was hit.&quot; , <span class="case">
|<div class="fraction">
<span class="fup">
d<sub>offset</sub>
</span>
<span class="fdn">
p<sub>target</sub>
</span>
</div>|&thinsp;&lt;&thinsp;ε
</span>
</span>
<span>
The projectile fell short. , <span class="case">
d<sub>offset</sub>&thinsp;&lt;&thinsp;0
</span>
&quot;The projectile fell short.&quot; , <span class="case">
d<sub>offset</sub>&thinsp;&lt;&thinsp;0
</span>
</span>
<span>
The projectile went long. , <span class="case">
d<sub>offset</sub>&thinsp;&gt;&thinsp;0
</span>
&quot;The projectile went long.&quot; , <span class="case">
d<sub>offset</sub>&thinsp;&gt;&thinsp;0
</span>
</span>
</div></em>
</div>
Expand Down

0 comments on commit 88119e4

Please sign in to comment.