Using zref-savepos within \newenvironment - latex

I've defined
\usepackage{zref-savepos}
\newcommand*{\curypos}[1]{%
\zsaveposy{#1}%
\zposy{#1}sp = %
\the\dimexpr\zposy{#1}sp\relax%
}
and that seems to work fine. Saying \curypos{some_label} reports the y position on the page, just as expected.
Now do
\newenvironment{mytest}[2]
{\write\myfile{\curypos{#1} #2}%
}
{% Do nothing to close out the environment.
}
\begin{mytest}{first}{second}
pointless blather
\end{mytest}
The contents of \myfile do not show the y-position on the page. Instead they show
\zsaveposy {first}0sp = 0.0pt second
For some reason, first is not passing through as an argument to \curypos.
I'm guessing that this is some form of fragility, so I tried using \protect in various places and declaring \curypos with \DeclareRobustCommand, but none of them work.

This isn't a complete answer, but I think the problem is due to the fact that the call to \zsaveposy is made from within a \write. My guess is that these write operations are treated as though they take place at the top (or bottom?) of the page so that the position is always (0,0). Breaking up the definition of the environment command as follows works.
\newenvironment{intfig}[2]
{\zsaveposy{#1}%
\write\myfile{\the\dimexpr\zposy{#1} #2 }%
}
{% nothing
}

Related

Lua - table won't insert from function

I have a Lua function where I build a table of value and attempt to add it to a global table with a named key.
The key name is pulled from the function arguments. Basically, it's a filename, and I'm pairing it up with data about the file.
Unfortunately, the global table always comes back nil. Here's my code: (let me know if you need to see more)
(Commented parts are other attempts, although many attempts have been deleted already)
Animator = Class{}
function Animator:init(atlasfile, stringatlasfriendlyname, totalanimationstates, numberofframesperstate, booleanstatictilesize)
-- Define the Animator's operation mode. Either static tile size or variable.
if booleanstatictilesize ~= false then
self.isTileSizeStatic = true
else
self.isTileSizeStatic = false
end
-- Define the total animation states (walking left, walking right, up down, etc.)
-- And then the total frames per state.
self.numAnimationStates = totalanimationstates or 1
self.numAnimationFrames = numberofframesperstate or 2
-- Assign the actual atlas file and give it a programmer-friendly name.
self.atlasname = stringatlasfriendlyname or removeFileExtension(atlasfile, 'animation')
generateAnimationQuads(atlasfile, self.atlasname, self.numAnimationStates, self.numAnimationFrames)
end
function generateAnimationQuads(atlasfile, atlasfriendlyname, states, frames)
spriteWidthDivider = atlasfile:getWidth() / frames
spriteHeightDivider = atlasfile:getHeight() / states
animationQuadArray = generateQuads(atlasfile, spriteWidthDivider, spriteHeightDivider)
animationSetValues = {atlasarray = animationQuadArray, width = spriteWidthDivider, height = spriteHeightDivider}
--gAnimationSets[#gAnimationSets+1] = atlasfriendlyname
gAnimationSets[atlasfriendlyname] = animationSetValues
--table.insert(gAnimationSets, atlasfriendlyname)
end
Note: when using print(atlasfriendlyname) and print(animationSetValues), neither are empty or nil. They both contain values.
For some reason, the line(s) that assign the key pair to gAnimationSets does not work.
gAnimationSets is defined a single time at the top of the program in main.lua, using
gAnimationSets = {}
Animator class is called during the init() function of a character class called Bug. And the Bug class is initialized in the init() function of StartState, which extends from BaseState, which simply defines dummy init(), enter(), update() etc. functions.
StartState is invoked in main.lua using the StateMachine class, where it is passed into StateMachine as a value of a global table declared in main.lua.
gAnimationSets is declared after the table of states and before invoking the state.
This is using the Love2D engine.
Sorry that I came here for help, I've been picking away at this for hours.
Edit: more testing.
Trying to print the animationQuadArray at the index gTextures['buganimation'] always returns nil. Huh?
Here's gTextures in Main.lua
gTextures = {
['background'] = love.graphics.newImage('graphics/background.png'),
['main'] = love.graphics.newImage('graphics/breakout.png'),
['arrows'] = love.graphics.newImage('graphics/arrows.png'),
['hearts'] = love.graphics.newImage('graphics/hearts.png'),
['particle'] = love.graphics.newImage('graphics/particle.png'),
['buganimation'] = love.graphics.newImage('graphics/buganimation.png')
}
Attempting to return gTextures['buganimation'] returns a file value as normal. It's not empty.
My brain is so fried right now I can't even remember why I came to edit this. I can't remember.
Global table in Main.lua, all other functions can't access it.
print(gTextures['buganimation']) works inside the function in question. So gTextures is absolutely accessible.
Table isn't empty. AnimationSetValues is not empty.
I'm adding second answer because both are correct in context.
I ended up switching IDE's to VS Code and now the original one works.
I was originally using Eclipse LDT with a Love2D interpreter and in that environment, my original answer is correct, but in VS Code, the original is also correct.
So Dimitry was right, they are equivalent, but something about my actual Eclipse setup was not allowing that syntax to work.
I switched to VS Code after I had another strange syntax problem with the interpreter where goto syntax was not recognized and gave a persistent error. The interpreter thought goto was the name of a variable.
So I switched, and now both things are fixed. I guess I just won't use LDT for now.
Solution: Lua syntax. Brain Fry Syndrome
I wrote:
animationSetValues = {atlasarray = animationQuadArray, width = spriteWidthDivider, height = spriteHeightDivider}
Should be:
animationSetValues = {['atlasfile']=atlasfile, ['atlasarray']=animationQuadArray, ['width']=spriteWidthDivider, ['height']=spriteHeightDivider}
Edit: I'm fully aware of how to use answers. This was posted here to reserve my spot for an answer so I could edit it later when I returned back home, which is exactly what I'm doing right now. I'll keep the old post for archival purposes.
Original:
I solved it. I apologize for not posting the solution right now. My brain is melted into gravy.
I will post it tomorrow. Just wanted to "answer" saying no need to help. Solved it.
Solution is basically, "oh it's just one of those Lua things". Wonderful. I'm having so much fun with this language - you can tell by my blank expression.
From the language without line endings or brackets, but forced print parentheses... ugh. I'm going back to C# when this class is done.

Prestashop all translatable-field display none for product page

Just new in Prestashop (1.6.0.6), I've a problem with my product page in admin. All translatable-field are to display:none (I inspect the code with chrome).
So when I want to create a new product I can't because the name field is required.
I thought that it was simple to find the .js whose do that but it isn't.
If somebody could help me, I would be happy.
Thank you for your help
Hi,
I make some searches and see that the function hideOtherLanguage(id) hide and show translatable-field element.
function hideOtherLanguage(id)
{
console.log(id_language);
$('.translatable-field').hide();
$('.lang-' + id).show();
var id_old_language = id_language;
id_language = id;
if (id_old_language != id)
changeEmployeeLanguage();
updateCurrentText();
}
When I set the Id to 1 (default language), it works. It seems that when I load the page, the function is called twice and the last calling, the id value is undefined. So the show() function will not work.
If somebody could help me. Thank you.
In my console, I see only one error
undefined is not a function.
under index.php / Line 1002
...
$("#product_form").validate({
...
But I find the form.tpl template and set this lines in comment but nothing change.
EDIT: According to comment on this link http://forge.prestashop.com/browse/PSCFV-2928 this can possibly be caused by corrupted installation file(s) - so when on clean install - try to re-download and reinstall...
...otherwise:
I got into a similar problem - in module admin page, when creating configuration form using PrestaShop's HelperForm. I will provide most probable cases and their possible solutions.
The solution for HelperForm was tested on PS 1.6.0.14
Generally there are 2 cases when this will happen.
First, you have to check what html you recieve.
=> Display source code - NOT in developer tools/firebug/etc...!
=> I really mean the pure recieved (JavaScript untouched) html.
Check if your translatable-fields have already the inline style "display: none":
Case 1 - fields already have inline style(s) for "display: none"
This means the template/html was already prepared this way - most probably in some TPL file I saw codes similar to these:
<div class="translatable-field lang-{$language.id_lang}"
{if $language.id_lang != $id_lang_default}style="display:none"{/if}>
Or particularly in HelperForm template:
<div class="translatable-field lang-{$language.id_lang}"
{if $language.id_lang != $defaultFormLanguage}style="display:none"{/if}>
Case 1 is the most easy to solve, you just have to find, where to set this default language.
Solutions
HelperForm
Look where you've (or someone else) prepared the HelperForm object - something like:
$formHelper = new HelperForm();
...
Somewhere there will be something like $formHelper->default_form_language = ...;
My wrong first solution was to get default form language from context - which might not be set:
$this->context->controller->default_form_language; //THIS IS WRONG!
The correct way is to get the default language from configuration - something like:
$default_lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$formHelper->default_form_language = $default_lang->id;
...this particularly solved my problem...
Other form-creations
If there is something else than HelperForm used for form creations, the problem is still very similar.
You have to find where in files(probably tpls) is a condition for printing display:none for your case - then find where is the check-against-variable set and set it correctly yourself.
Case 2 - fields don't have inline style(s) for "display: none"
This means it is done after loading HTML by JavaScript. There are two options:
There is a call for hideOtherLanguage(), but there is wrongly set input language - that means no language will be displayed and all hidden.Solution for this one can be often solved by solving Case 1 (see above). In addition there can be programming error in not setting the after-used language id variable at all... then you would have to set it yourself (assign in JavaScript).
Some script calls some sort of .hide() on .translatable-field - you will have to search for it the hard way and remove/comment it out.
PS: Of course you can set the language to whatever you want, it is just common to set it to default language, because it is the most easier and the most clear way how to set it.

How to keep TYPO3's RTE from adding an empty line before <ul>s

In TYPO3 4.5 as well as 6.1, whenever I add an unordered list element, RTEhtmlarera (or some of its many processing routines) will add an extra
<p> </p>
before the ul tag on saving the content element.
This happens only once, when the ul is inserted first. When the p tag is removed and the content element is saved again, it won't happen again.
How can this erroneous behaviour be removed?
Hi try set encapsLines to zero..
Setup typoscript:
tt_content.stdWrap.dataWrap >
lib.parseFunc_RTE.nonTypoTagStdWrap.encapsLines >
Not a real solution but maybe a hint in the right direction.
If you write down your list, do not press enter before the first list entry but shift+enter.
Example:
Here comes the list: <<-- AT THIS POINT PRESS SHIFT+ENTER
- a <<-- Here it does not matter if you press enter or shift+enter
- b
- c
- ...
This works for me as a workaround. I've done a lot of research in sysext:rtehtmlarea but nothing worked. So this looks for me like some kind of mysterious bug/feature connected with the "BR to P" (or vice versa) configuration you can define in pageTS or Setup. BTW: I never fully understood this conversion-thing :)
For me with 6.1 this worked:
lib.parseFunc_RTE {
externalBlocks = table, blockquote, ol, ul, div, dl, address, hr
externalBlocks {
ol.stripNL=1
ol.stdWrap.parseFunc = < lib.parseFunc
ul.stripNL=1
ul.stdWrap.parseFunc = < lib.parseFunc
# i have also seen this setting, but didnĀ“t test it:
# blockquote.stripNLprev = 1
# blockquote.stripNLnext = 1
}
}
I removed many lines for this example, be aware that you overwrite previous settings by using {} ..

emacs smart-tab with yasnippets

I'm trying to get tab complete within all open buffers and yasnippet to both work with the tab key. At the moment I can have one or the other. The following code is how I'm handling the yasnippet expand, but as I'm not a lisp programmer I cannot see the mistake here.
If it cannot expand the snippet I would like it to try and expand from the buffer.
;; Auto complete settings / tab settings
;; http://emacsblog.org/2007/03/12/tab-completion-everywhere/ <-- in the comments
(global-set-key [(tab)] 'smart-tab)
(defun smart-tab ()
"This smart tab is minibuffer compliant: it acts as usual in
the minibuffer. Else, if mark is active, indents region. Else if
point is at the end of a symbol, expands it. Else indents the
current line."
(interactive)
(if (minibufferp)
(unless (minibuffer-complete)
(dabbrev-expand nil))
(if mark-active
(indent-region (region-beginning)
(region-end))
(if (looking-at "\\_>")
(unless (yas/expand)
(dabbrev-expand nil))
(indent-for-tab-command)))))
First, I try to understand what the code does, and what you would like it does.
Your code
first checks if the point is in the minibuffer.
If so, then it tries to complete the minibuffer
if (in minibuffer) cannot complete it, it calls dabbrev-expand
else if the point is not in minibuffer
if some region is marked , it indents the region.
if no mark is active, it checks to see if the point is at the end of some word
if so, it checks is yasnippet can expand.
if yas cannot expand, it calls dabbrev-expand
if not, it tries to indent the current line
This is what your code does.
Your code fails due to yas/expand. This command does not return in case the expansion fails.
In case that this command fails, it checks the state of the variable yas/fallback-behavior. If this variable has the value call-other-command, as in your case, the failed yas expansion calls the command bound to the key kept in the variable yas/trigger-key.
In your case , this variable is TAB.
So: You are at the end of the word, You press TAB to complete it, this triggers the interactive smart-tab, which calls yas/expand which in case it fails to expand calls the bound function of TAB, and here is the infinite loop.
The Solution for your problem is to temporaily bound nil to yas/fallback-behavior in this smart-tab function.
Here is how to fix it:
(if (looking-at "\\_>")
(let ((yas/fallback-behavior nil))
(unless (yas/expand)
(dabbrev-expand nil)))
(indent-for-tab-command))

ActionScript Unexpected Curly Braces/Semicolon?

I'm editing an ActionScript file and I've run into an issue.
When I put the following, everything is fine.
if (x=x) {
//blah
}
If I put this, it says unexpected ; for one line and } for the another:
for (x=x) {
//blah
}
Same with when I put this:
while (x=x) {
//blah
}
Of course I only put those there as examples to test it, because I thought something was wrong with my code. Is ActionScript, in this part of my file, only allowing IF statements or what? I need to do the same long series of steps to two different strings, but I don't want to put the code in there twice. Do I have to make a function?
Read up on the looping syntax here.
The For loop doesn't take a boolean (true/false), it needs a counter, a boolean check for the limit and an increment.
i.e.
for (counter; condition; action){
statements;
}
I've never used action script but I would suggest trying this with
x==x
Since once = is assignment, not a comparison.
if the for loop still does not function try
for(;x==x;){
}
the semicolons tell it that you want to only use the second statement in the for loop declaration, the condition; since for loops use three statements,
for (variable; condition; iterative action)
by placing semicolons before and after x==x you specify only the condition, which seems to be what you're trying to do.
Turns out using any IF or WHILE statements caused the error no matter what was inside.
I was able to accomplish what I wanted by making another function and sending each string though those.
Appreciate the help, voted up on both of y'all.
you have to write it like this:
if(a==x){
// do that
}
for (x=0; x<maxloops; x++){
// do that
}
while(a==x){
}
The = symbol is used to define values to varialbes, while == has to be used when you comparing / checking (i.e. whether this is equal to that). This both applies to IF and WHILE
the FOR LOOP. Let's say that you want to execute the action "do that" 10 times. then you write
for (x=0; x<10; x++){
// do that
}
the first part x=0 is the definition of the counting variable and its initial value
the second part is the condition (run the loop as long as x is less than 10)
the third part is the stepper. (how the counter will raise its value in each loop). x++ is a short way to write x = x +1;

Resources