Latex listings package ignores last blank line in listing - latex

I use LaTeX listings package with \lstinputlisting to display text from an external file. The file contains a data format description with a blank line at the end. The package ignores the blank line. How can I show the blank line in a listing?
What it displays:
1 lorem ipsum...
2 more lorem ipsum
3 lorem lorem ipsum
What I want:
1 lorem ipsum
2 more lorem ipsum
3 lorem lorem ipsum
4

See the documentation, section 4.4
`showlines=(true|false) or showlines (default = false)
If true, the package prints empty lines at the end of listings. Otherwise these lines are dropped (but they count for line numbering).
Try adding this before your listing:
\lstset{
showlines=true
}

You can escape to LaTeX from within listings by assigning an escape character like so:
\lstset{numbers=left, stepnumber=1, frame=none,basicstyle = \ttfamily}
\begin{lstlisting}[escapechar=\%]
codeline1
codeline2
%
\end{lstlisting}
Comes out as:
1 codeline1
2 codeline2
3
I know it's not \lstinputlisting but hopefully it'll help you anyway.

Related

Generate x characters worth of Lorem Ipsum text (sentences and paragraphs)?

I have a User field called 'bio' that can be up to 800 characters (as well as some other free text fields of varying lengths). Having it populate with dummy text would help assess the visuals/design of the front end.
How can I generate 800 characters worth of Lorem Ipsum text to place into that field? By 'Lorem Ipsum text' I mean sentences and paragraphs (not just 800 characters worth of sentences in one giant paragraph).
"a"*800 is not varied enough to resemble human paragraphs.
Note: this is for the seeds.rb file, and I am already using faker gem, in case that's useful.
I'm sure there are better ways, but this uses the Faker gem and looks quite natural:
def make_natural_text(n)
paras = ""
until paras.length > n
para = Faker::Lorem.paragraphs(number: (2..7).to_a.sample(1)[0]).join + "\n\n"
paras += para
end
paras[0..(n-1)]
end
natural_text = make_natural_text(800)
puts natural_text

How to load local files in a WKWebView after downloading them (not in the bundle), and with params in the url?

I have tried to download files, and to load them in a WKWebView.
If I load them with and .html file it is okay, but when I want to indicate a param to go directly to a specific webpage, it doesn't load the page. It gives me a white page.
How to put params in the url and load it in the WKWebView?
let url = Constants.Path.document + "/APP/index.html?180&2"
let nsurl = URL(fileURLWithPath: url) //locally
let readAccessToURL = nsurl.deletingLastPathComponent()
webView?.loadFileURL(nsurl, allowingReadAccessTo: readAccessToURL)
(If I load it only with index.html, it works and if I use a UIWebView with the same url with params, it works)
Thanks in advance
Can you try with using # instead of ? while preparing the url? One more thing - as I can see your resource is located on your device you may need to prefix "file://" before your full path. I was able to load with a pre-selected anchor following that. I tried with an html file in my Bundle.main
class ViewController: UIViewController {
var webView: WKWebView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let weburl = "file://" + Bundle.main.path(forResource: "WebContent", ofType: "html")! + "#Lorem_Ipsum4"
// Web view
webView = WKWebView()
webView!.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(webView!)
webView!.widthAnchor.constraint(equalTo: view.widthAnchor, constant: 0.0).isActive = true
webView!.heightAnchor.constraint(equalTo: view.heightAnchor, constant: 0.0).isActive = true
webView!.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0).isActive = true
webView!.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0).isActive = true
webView?.load(URLRequest(url: URL(string: weburl)!))
}
}
And this is my WebContent.html.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.main-content {
height: 100vh;
text-align: justify;
}
</style>
</head>
<body>
<h2 id="Lorem_Ipsum1">Lorem Ipsum</h2>
<p class="main-content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
</p>
<h2 id="Lorem_Ipsum2">Lorem Ipsum</h2>
<p class="main-content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
</p>
<h2 id="Lorem_Ipsum3">Lorem Ipsum</h2>
<p class="main-content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
</p>
<h2 id="Lorem_Ipsum4">Lorem Ipsum</h2>
<p class="main-content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
</p>
<p>Go to the
top.
</p>
</body>
</html>

How to Search for a few words with a character that changes its position in the cell?

I'm trying to figure out how to search to replace text containing a word, e.g: "This Is My Name!" that also may contain an extra character, in my case, the character "/".
So for example, I'd like to be able to use the search and replace functionality to match this sentence:
This Is My Name! - blah blah / abc 123 ipsum
As well as this sentence:
ipsum lorem $999 - 3 / This Is My Name! $55
Or this:
ipsum lorem $999 - 3 / This Is My Name! $55 / Ipsum Lorem - (34)
I'm assuming some form of regex?
Thank you.
Solution
Based on examples you have provided:
=ArrayFormula(REGEXREPLACE(A1:A3,"^This Is My Name!|/ This Is My Name!","SOMETHINGNEW"))
Picture
Some explanation:
Regex is looking for
^This Is My Name!. ^ before your string means that text should start with your string
OR (this is represented by |)
/ This Is My Name! - which is your text and an extra character
ArrayFormula is added to populate formula down (in A1:A3) range
Helpful?

Ruby regex to convert uppercased words and keep titleized ones

Given string "Lorem IPSUM dolor Sit amet". Capital letters in "Lorem" and "Sit" should be kept, uppercased ones like "IPSUM" should be converted to "Ipsum"
How to make "Lorem Ipsum dolor Sit amet" from given string using gsub?
NOT working example: s.gsub(/[[:upper:]]/){$&.downcase}
You may use capitalize with /\b[[:upper:]]{2,}\b/ regex:
s.gsub(/\b[[:upper:]]{2,}\b/){$&.capitalize}
# => Lorem Ipsum dolor Sit amet
See the online Ruby demo.
Note that the \b[[:upper:]]{2,}\b pattern will match whole words (as \b are word boundaries) that only consist of 2 or more uppercase letters (there seems no need to match words like I that are already OK).

Ruby gem for text comparison

I am looking for a gem that can compare two strings (in this case paragraphs of text) and be able to gauge the likelihood that they are similar in content (with perhaps only a few words rearranged, changed). I believe that SO uses something similar when users submit questions.
I'd probably use something like Diff::LCS:
>> require "diff/lcs"
>> seq1 = "lorem ipsum dolor sit amet consequtor".split(" ")
>> seq2 = "lorem ipsum dolor amet sit consequtor".split(" ")
1.9.3-p194 :010 > Diff::LCS.diff(seq1, seq2).length
=> 2
It uses the longest common subsequence algorithm (the method for using LCS to get a diff is described on the wiki page).

Resources