BiBtex line break - bibtex

I edited an BibteX file and it works so far that it shows all information I need.
FUNCTION {electronic}
{ output.bibitem
format.btitle "title" output.check
url output
format.date "year" output.check
fin.entry
empty.misc.check
}
with
#Electronic{L2PwikiAAS,
title = {Wiki des L2P-Lernraumes},
year = {05.12.2016},
url = {https://~/collaboration/Lists/WikiList1/Atomabsorptionsspektroskopie%20(AAS).aspx},
}
but the URL is very long and it goes over the end of the page.
What should I do to get a linebreak somewhere in this URL?
And how can I add the string 'Zuletzt aufgerufen am:' before the date?
Thanks in advance

You can add characters, after which a line break is allowed: https://norwied.wordpress.com/2012/07/10/how-to-break-long-urls-in-bibtex/
Just add e.g.: \def\UrlBreaks{\do\/\do-} right after \PassOptionsToPackage{hyphens}{url}\usepackage{hyperref}

Related

Best way to get arguments from string by user for chat bot

I need to accept 2 arguments: first is time argument for example "1m", "2h 42m", "1d 23h 3s", second is text. I thought I can just convert input string to array and split it into 2 array using regex maybe, first with "d", "h", "m" and "s", second everything else and convert in back to string. but then I realize I'll need 3rd argument which gonna be optional target channel (dm or current channel, where command been executed), and also what if user want to include 1m in his text (it's reminder command)
The easiest way to do this is to have the user seperate each argument by a comma. Although this creates the issue where the user can't user a comma in their text part. So if that isn't an option, another way to do it is to get the message content and start by stripping parts of it away. You begin by grabbing the time portion with a regex. Then you look for channel mentions and strip those away. What you're left with should solely be the text.
Below is some (non-tested) code which could lead you in the right direction. Give it a try and let me know if you have any problems
let msg = {
content: "1d 3h 45m 52s I feel like 4h would be to long <#222079895583457280>",
mentions: {
channels: ['<#222079895583457280>']
}
};
// Mocked Message object for testing purpose
let messageObject = {
mentions: {
CHANNELS_PATTERN: /<#([0-9]+)>/g
}
}
function handleCommand (message) {
let content = message.content;
let timeParts = content.match(/^(([0-9])+[dhms] )+/g);
let timePart = '';
if (timeParts.length) {
// Get only the first match. We don't care about others
timePart = timeParts[0];
// Removes the time part from the content
content = content.replace(timePart, '');
}
// Get all the (possible) channel mentions
let channels = message.mentions.channels;
let channel = undefined;
// Check if there have been channel mentions
if (channels.length) {
channel = channels[0];
// Remove each channel mention from the message content
let channelMentions = content.match(messageObject.mentions.CHANNELS_PATTERN);
channelMentions.forEach((mention) => {
content = content.replace(mention, '');
})
}
console.log('Timepart:', timePart);
console.log('Channel:', channel, '(Using Discord JS this will return a valid channel to do stuff with)');
console.log('Remaining text:', content);
}
handleCommand(msg);
For the messageObject.mentions.CHANNEL_PATTERN look at this reference

How do I get the text from the li tag

How do I get the text from the li tag? I want to find the text "Password is required." only, not the text inside strong tag.
<li><strong>Error:</strong> Password is required.</li>
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] {">","<"});
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child) {
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
}
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).

Swift 4 Replace word within String

The setup: A UITextField and a Tableview with suggested users
I try to have the following result:
I want users to be able to link other users.
Its working fine as long as I search with my last word in the array
let caption = captionTextView.text
let words = caption?.components(separatedBy: .whitespacesAndNewlines)
guard let searchingWord = words?.last else {return}
if searchingWord.hasPrefix("#") {
self.indicator.startAnimating()
let search = searchingWord.trimmingCharacters(in: CharacterSet.punctuationCharacters).lowercased()
}
But in case a user wants to adjust a username in the middle or at least not at the end of the array, the searching functions doesn't work properly as it still searches with the last word in the array
Example:
"Hey how are you #Lisa #Marcel #Thomas"
In case a user wants to change "#Lisa" to "#Lisbeth" the search function will search with Thomas as its the last word in the array
I wasn't able to get the word I am working at, only last and first words in the array, however I am able to get the current cursor location with
let cursor = captionTextView.cursorOffset!
which is an extension.
So how do I get the word I am working at up until the next "#" to the left und the next blank space to the right? Thanks in advance!
Maybe try something like this:
if let selectedRange = textview.selectedTextRange {
let cursorOffset = textview.offset(from: textview.beginningOfDocument, to: selectedRange.start)
let text = textview.text
let substring = text?.prefix(cursorOffset)
let editedWord = substring?.split(separator: "#")
}
(written on a phone, and untested)
One solution is Regular Expression
let string = "Hey how are you #Lisa #Marcel #Thomas"
let searchingWord = "Lisa"
let replacingWord = "Lisbeth"
let pattern = "#\(searchingWord)\\s"
string.replacingOccurrences(of: pattern, with: "#\(replacingWord) ", options: .regularExpression)
The pattern searches for # followed by the searching word followed by a whitespace character.
Since you say things are working the way you want if the last word is the one that has a username in it you just need to loop over all the words. Depending on your needs you may need to keep track of the usernames that were in the text before to save you from searching for the same user multiple times, but an array of used usernames should sort that for you.
Also, unless you want to prevent users from having underscores and the such in their names you should tweak the way in which you remove the # symbol as well.
guard let words = captionTextView.text?.components(separatedBy: .whitespacesAndNewlines) else { return }
for word in words where word.hasPrefix("#") {
self.indicator.startAnimating()
let search = word.replacingOccurrences(of: "#", with: "").lowercased()
}
Sticking the above code into a playground that uses the sample string you supplied in place of captionTextView.text? and printing search each time yielded…
lisa
marcel
thomas

How to loop TextFragment in Aspose.PDF

In a process of writing text to PDF, I'm using TextFragment for setting properties of various fields. Instead of setting for each field separately, how do make use of a loop?
My present code:
TextFragment a = new TextFragment("Hi!");
tf.setPosition(dropDown);
tf.getTextState().setFont(new FontRepository().findFont("Arial"));
tf.getTextState().setFontSize(10.0F);
.
.
.
TextFragment n = new TextFragment("n");
tf.setPosition(dropDown);
tf.getTextState().setFont(new FontRepository().findFont("Arial"));
tf.getTextState().setFontSize(10.0F);
I need something like this:
some loop {
.
.
TextFragment txtFrag = new TextFragment(A);
tf.setPosition(dropDown);
tf.getTextState().setFont(new FontRepository().findFont("Arial"));
tf.getTextState().setFontSize(10.0F);
} //This should set properties for all fields
The string in TextFragment("String") is not same for all the fields. It's different for various form fields.
You may simply add text fragments in your PDF file and once you finish adding text, you may get or set different properties for all the text fragments in a PDF file by using the code below:
// Load document
Document document = new Document( dataDir + "input.pdf");
// Create TextAbsorber object to extract all textFragments
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber();
// Accept the absorber for first page of document
document.getPages().accept(textFragmentAbsorber);
// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
// Loop through the Text fragments
for (TextFragment textFragment : (Iterable<TextFragment>) textFragmentCollection) {
// Iterate through text fragments
System.out.println("Text :- " + textFragment.getText());
textFragment.getTextState().setFont(new FontRepository().findFont("Arial"));
textFragment.getTextState().setFontSize(10.0F);
System.out.println("Position :- " + textFragment.getPosition());
System.out.println("XIndent :- " + textFragment.getPosition().getXIndent());
System.out.println("YIndent :- " + textFragment.getPosition().getYIndent());
System.out.println("Font - Name :- " + textFragment.getTextState().getFont().getFontName());
}
// Save generated document
document.save(dataDir + "input_17.12.pdf");
You may visit Working with Text for more information on this. I hope this will be helpful. Please let us know if you need any further assistance.
I work with Aspose as Developer Evangelist.

RESTEasy: getPathSegments().get(1);

Can someone tell me what "PathSegment model = info.getPathSegments().get(1);" do, specifically, what does he getPathSegments().get(1) mean? Please provide a sample URL for demonstration. The book didn't give an example URL for this one.
Also, is there such a thing as get(0); ?
#Path("/cars/{make}")
public class CarResource
{
#GET
#Path("/{model}/{year}")
#Produces("image/jpeg")
public Jpeg getPicture(#Context UriInfo info)
{
String make = info.getPathParameters().getFirst("make");
PathSegment model = info.getPathSegments().get(1);
String color = model.getMatrixParameters().getFirst("color");
...
}
}
Thanks again,
If you split the path of a URL by a '/' you'll get a list of path-segments. So e.g. the path /cars/ford/mustang/1976 contains the four segments [cars, ford, mustang, 1976]. info.getPathSegments().get(1) should return the segment ford.
The PathSegment holds also the associated MatrixParameters of the current segment. MatrixParameters can be used if you want to filter the resources with a parameter that affects only one segment like here:
/cars/ford/mustang;generation=two/1976

Resources