How to prevent substitution with two instances of C++ in an asciidoctor sentence? - asciidoctor

If C++ appears just once in a sentence, asciidoctor parses the string just fine.
If C++ appears twice, asciidoctor matches across bar in the example below.
Various attempts at preventing substitutions do not work.
How can one typeset C++ two or more times in a sentence using asciidoctor?
. foo C++
. foo C++ bar C++ blah
. foo C\++ bar C++ blah
. foo C+\+ bar C++ blah
. foo C\+\+ bar C++ blah
. foo C+\+ bar C\++ blah
. foo C+\+ bar C+\+ blah
. foo C\\++ bar C\\++ blah
. foo C\\++ bar C++ blah

The built-in attributes are needed.
The following four samples are correctly parsed.
. {cpp}
. {cpp} and {cpp}
. `{cpp}`
. `{cpp}` and `{cpp}`
producing
Though there may be a bug lurking somewhere.
If you want to write c++ (in small letters), precede the lines above with :cpp: c++.

Related

Why does this code not parse without whitespace?

So I am learning Monads and was playing around with the following expression:
[1,2] >>= \x -> ['a','b'] >>= \y -> return (x,y)
The above code produces the result [(1,a),(1,b),(2,a),(2,b)] as expected.
But since I was just experimenting, I got lazy and I entered:
[1,2]>>=\x->['a','b']>>=\y->return (x,y) (same code as above but without white-spaces)
which doesn't seem to work.
I understand that if I properly bracket out this expression as
[1,2]>>=(\x->(['a','b']>>=(\y->return (x,y))))
it will work (better I just put spaces than these monstrous brackets) but I don't get why the expression with white-space works whereas the other one doesn't.
You need spaces to separate identifier names: foo bar is two separate names, whereas foobar (without the space) is just one name.
The same thing happens with operators. Haskell allows arbitrary user-defined operators; if you want to write a function named ??++!?!, then go for it! But you must use spaces to separate operators from one another.
Just as >>= is not the same thing as >> =, so >>=\ isn't the same as >>= \. You could actually define a function named >>=\ if you wanted. But the space lets the Haskell language parser know this is two things, not one.
To fully understand this, you need to look at Chapter 2 of the Haskell Report, particularly section 2.4. The lexeme -> is a reservedop, >>= is not.
For example, does this expression require a space, or spaces?
[1,2]>>=return
[1,2] >>=return

Vim: Is there a better way to navigate a "select from list" dialog?

Fairly often, I'll want to use g] or :tsel to pick one tag out of several. This brings up the little interactive prompt that you may have seen:
# pri kind tag file
1 F C c MyClass /path/to/MyClass.java
bla bla Identifier line A
2 F c MyClass /path/to/MyClass.java
bla bla Identifier line B
3 F c MyClass /path/to/MyClass.java
bla bla Identifier line C
Type number and <Enter> (empty cancels):
If the list is short, this is okay. But often, in my situations, I have a long list, and at the bottom will be:
-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit
Is there any way I can choose an item without typing a number?
Perhaps some sort of visual select?
Or maybe dump the output into the quickfix list, so I can poke around in there, rather than having the list go away as soon as I make a choice?
Also: can anyone tell me where this kooky little dialog is documented in :help ?
Edit: I found :help :tsel and :help more-prompt to have the most info so far. Anyone know others?

Pass arguments from csh to program, exactly as they are

I have a csh script, which is executed using "source", and passes all its arguments to a program:
% alias foo source foo.csh
% cat foo.csh
./bar $*
# Some uninteresting stuff
If I run source foo.csh a b c, all is OK. But not always:
foo "a b" "c d":
I expect bar to get two arguments - a b and c d. Instead, it gets 4.
foo a "*" b:
The * is expanded to a list of files. I just want the character *.
Extra credit - foo a * b should work the same way. I know it's more problematic and I'm willing to live without it.
One thing I tried is changing ./bar $* to ./bar "$*". This helps with the asterisk, but now bar always gets everything in a single parameter.
Notes:
Our company uses csh as the login shell, so I must use it when using source. Knowing that csh programming is considered harmful, I implemented all logic in bar and left the bare minimum in the script.
If you suggest redefining the alias, it's important to see that redirection still works (foo | grep hello), and that there's proper cleanup if ctrl-C breaks the script.
Meanwhile, I've found the answer myself:
./bar $argv:q
The :q modifier takes care of things. It passes to bar the exact same parameters foo got.
Source: http://www.staff.tugraz.at/reinfried.o.peter/unix/cshell.html

How to make Haskell or ghci able to show Chinese characters and run Chinese characters named scripts?

I want to make a Haskell script to read files in my /home folder. However there are many files named with Chinese characters, and Haskell and Ghci cannot manage it. It seems Haskell and Ghci aren't good at displaying UTF-8 characters.
Here is what I encountered:
Prelude> "让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档"
"\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723"
Prelude> putStrLn "\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723"
让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档
GHC handles unicode just fine. These are the things you should know about it:
It uses your system encoding for converting from byte to characters and back when reading from or writing to the console. Since it did the conversion from bytes to characters properly in your example, I'd say your system encoding is set properly.
The show function on String has a limited output character set. The show function is used by GHCI to print the result of evaluating an expression, and by the print function to convert the value passed in to a String representation.
The putStr and putStrLn functions are for actually writing a String to the console exactly as it was provided to them.
Thanks to Carl, i used putStrLn as a wrapper around my fuction:
ghci> let removeNonUppercase st = [c | c <- st, c `elem` ['А'..'Я']]
ghci> putStrLn (removeNonUppercase "Ха-ха-ха! А-ха-ха!")
ХА
Everything works fine!

Render any Literate Haskell to PDF, HTML, or similar

How to I convert a Literate Haskell file to something easier on the eyes? Here's what happens when I try to do the obvious thing:
$ latex Check.lhs
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(./Check.lhs
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
! LaTeX Error: Environment code undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.7 \begin{code}
I'm not familiar with the usual commands for processing tex files. What's a simple, no-nonsense way I can use to convert just about any .lhs file to e.g. PDF or HTML?
In this space you can use lhs2TeX, which has quite a few options but can give quite nice results on formatting. It has pretty extensive documentation, which you can find on the homepage.
An example of usage (directly from the manual) would be
\documentclass{article}
%include polycode.fmt
\begin{document}
This is the famous ‘‘Hello world’’ example,
written in Haskell:
\begin{code}
main :: IO ()
main = putStrLn "Hello, world!"
\end{code}
\end{document}
The \documentclass{article}, \begin{document} and \end{document} are all TeX commands to indicate what kind of document you want, and where it starts/ends.
The %include polycode.fmt is actually a comment in TeX, but will indicate to lhs2TeX what format to use when processing the .lhs file.
You can compile the example with
$ lhs2TeX -o HelloWorld.tex HelloWorld.lhs
$ pdflatex HelloWorld.tex
For HTML you can also try Pandoc, which can give you all sorts of output formats (pdf, html, rtf, etc).
You want to preprocess your literate files with lhs2tex.

Resources